PyQt5 QBoxLayout

Thu 12 October 2017 by Little Captain

QBoxLayout

An instance of the QBoxLayout divides the given space into boxes, where each box is totally filled with one exact widget. It can add widgets in vertical or horizontal direction, where the choice of vertical or horizontal depends on type of class the object is instanced from.

The class …

read more

PyQt5 Form Layout

Thu 12 October 2017 by Little Captain

Form Layout

A form can be created using the class QFormLayout. This is the easiest way to create a form where widgets (input) have descriptions (labels)

from PyQt5.QtWidgets import (QApplication, QComboBox, QDialog,
                             QDialogButtonBox, QFormLayout, QGridLayout, QGroupBox, QHBoxLayout,
                             QLabel, QLineEdit, QMenu, QMenuBar, QPushButton, QSpinBox, QTextEdit,
                             QVBoxLayout)

import sys


class Dialog …
read more

PyQt5 Directory View

Thu 12 October 2017 by Little Captain

Directory View

PyQt can show a directory structure using a QTreeView. For the treeview to show as a directory tree, we need to set its model to a QFileSystemModel instance. QTreeView combined with QFileSystemModel. That is achieved by calling the setModel method for the tree instance.

We can set additional …

read more

PyQt5 Treeview

Thu 12 October 2017 by Little Captain

Treeview

PyQt5 (python with qt5 bindings) supports a tree view widget (class QTreeView). In this article we will show how to use the widget.

import sys
from PyQt5.QtGui import QIcon

from PyQt5.QtCore import (QDate, QDateTime, QRegExp, QSortFilterProxyModel, Qt,
                          QTime)
from PyQt5.QtGui import QStandardItemModel
from PyQt5.QtWidgets import …
read more

PyQt5 browser

Thu 12 October 2017 by Little Captain

browser

PyQt5 supports a widget that displays websites named QWebView.

QWebView uses the Webkit rendering engine The web browser engine is used by Safari, App Store and many OS X applications.

The load() method opens the url (QUrl) in the argument. You can create a QUrl using: QUrl(url).

The …

read more

PyQt5 Matplotlib

Thu 12 October 2017 by Little Captain

Matplotlib

import sys

from PyQt5.QtWidgets import QApplication, QMainWindow, QMenu, QVBoxLayout, QSizePolicy, QMessageBox, QWidget, \
    QPushButton
from PyQt5.QtGui import QIcon

from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
import matplotlib.pyplot as plt

import random


class App(QMainWindow):
    def __init__(self):
        super().__init__()
        self.left …
read more

PyQt5 font dialog

Thu 12 October 2017 by Little Captain

font dialog

PyQt5 comes with a font dialog that you may have seen in a text editor. To open this dialog import QFontDialog call

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QFontDialog
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot


class App(QWidget):
    def __init__(self …
read more

PyQt5 drag and drop

Thu 12 October 2017 by Little Captain

drag and drop

Like any modern GUI toolkit, PyQt supports drag and drop. A widget parameter must be set using the setDragEnabled(True) method call. A custom widget should then be set to accept a drop with setAcceptDrops(True).

# Drag text from the input field to the label, the label …
read more

PyQt5 colors

Thu 12 October 2017 by Little Captain

colors

Colors in PyQt5 are defined using the method QColor(r, g, b). All colors on the screen are a combination of the red, green and blue values. Every color value should be in the range 0..255. In a QPainter widget you can pass a color to the setBrush …

read more

PyQT5 color dialog

Thu 12 October 2017 by Little Captain

color dialog

PyQt5 supports a color picker known as QColorDialog. This dialog is a typical dialog that you would see in a paint or graphics program.

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QColorDialog
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtGui import …
read more