PySide: QPushbutton Text below Icon

Apparently using a QPushbutton with an Icon does not work. As alternative, I am going to use a QToolbutton. [python] import sys from PySide.QtCore import * from PySide.QtGui import * class Widget(QWidget): def __init__(self, parent= None): super(Widget, self).__init__() layout = QVBoxLayout(self) #QToolButton btn = QToolButton() btn.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) btn.setText("test") btn.setIcon(btn.style().standardIcon(QStyle.SP_DirIcon)) btn.setIconSize(QSize(54,54)) layout.addWidget(btn) …

PySide: QVBoxLayout with QScrollArea

Here is an example that adds Scrollbars to a QVBoxLayout. The one thing that tripped me up was that you need to explicitly create a Widget for the QScrollArea. [python] import sys from PySide.QtCore import * from PySide.QtGui import * class Widget(QWidget): def __init__(self, parent= None): super(Widget, self).__init__() self.setFixedHeight(200) #Container …

PySide: QTreeListWidget deleting an Item, editing an Item

This example creates a QTreeListWidget to display a folder-structure. [python] import sys, os from PySide.QtCore import * from PySide.QtGui import * class TreeTest(QTreeWidget): def __init__(self, parent = None): super(TreeTest, self).__init__(parent) self.setColumnCount(1) self.setHeaderLabel("Folders") actionEdit = QAction("New Folder", self) actionEdit.triggered.connect(self.addItemAction) self.setContextMenuPolicy(Qt.ActionsContextMenu) self.addAction(actionEdit) actionDelete = QAction("Delete", self) actionDelete.triggered.connect(self.deleteItem) self.addAction(actionDelete) self.style() def addItem(self, name, …

PySide: Using standard system Icons

You can add Icons to many types of QWidgets. PySide provides you with a method to access the native system icons. A complete list of icons can be found here: PySide.QtGui.PySide.QtGui.QStyle.StandardPixmap To apply the QIcon you need to [python] btn = QPushButton("Folder") style = btn.style() icon = style.standardIcon(QStyle.SP_DirIcon) btn.setIcon(icon) #or …

PySide: QMessageBox with QCheckBox

The QMessageBox is very useful for creating standard filesystem dialogs (it even comes with alert sounds) and is limited to display an icon, text and standard buttons. If you want to add something extra like a checkbox for “do not ask me again”, you need to extend the base class. …

PySide: Rightclick Button Menu

PySide (www.pyside.org) is an awesome Framework that allows you to use Qt with Python. Installation is as straightforward as typing pip install pyside I will be creating a menu that opens with a right click. This menu is called “Context Menu” in QT. In this example, the right-click menu on …