Are there default icons in PyQt/PySide?

What you need is Pyside QIcon.fromTheme function. Basicaly it creates QIcon object with needed icon from current system theme. Usage: undoicon = QIcon.fromTheme(“edit-undo”) “edit undo” – name of the icon “type”https://stackoverflow.com/”function” can be found here This works on X11 systems, for MacOSX and Windows check QIcon documentation QIcon.fromTheme Edit Inserting this from the website, since … Read more

QListWidget and Multiple Selection

Unfortunately I can’t help with the Python specific syntax but you don’t need to create any subclasses. After your QListWidget is created, call setSelectionMode() with one of the multiple selection types passed in, probably QAbstractItemView::ExtendedSelection is the one you want. There are a few variations on this mode that you may want to look at. … Read more

PyQt Widget connect() and disconnect()

If you need to reconnect signals in many places, then you could define a generic utility function like this: def reconnect(signal, newhandler=None, oldhandler=None): try: if oldhandler is not None: while True: signal.disconnect(oldhandler) else: signal.disconnect() except TypeError: pass if newhandler is not None: signal.connect(newhandler) … if connected: reconnect(myButton.clicked, function_A) else: reconnect(myButton.clicked, function_B) (NB: the loop is … Read more

What’s the difference in Qt between setVisible, setShown and show/hide

show() is just a convenience function for setVisible(true). Similarly hide() is equivalent to setVisible(false) Internally, the same code is used to render your view. See http://doc.qt.io/archives/qt-4.7/qwidget.html#show as an example. According to it, void QWidget::show () [slot] Shows the widget and its child widgets. This function is equivalent to setVisible(true). You’ll find lots of such functions … Read more

Redirecting stdout and stderr to a PyQt4 QTextEdit from a secondary thread

Firstly, +1 for realising how thread-unsafe many of the examples on stack overflow are! The solution is to use a thread-safe object (like a Python Queue.Queue) to mediate the transfer of information. I’ve attached some sample code below which redirects stdout to a Python Queue. This Queue is read by a QThread, which emits the … Read more

Proper way to quit/exit a PyQt program

Calling QCoreApplication.quit() is the same as calling QCoreApplication.exit(0). To quote from the qt docs: After this function has been called, the application leaves the main event loop and returns from the call to exec(). The exec() function returns returnCode. If the event loop is not running, this function does nothing. [emphasis added] So quit() or … Read more

PyQt: Always on top

Pass the QMainWindow the WindowStaysOnTopHint window flag (or use setWindowFlags). As in the name, this is a hint to the windowing manager (not a hard guarantee). Simplest possible example: import sys from PyQt4 import QtGui, QtCore class mymainwindow(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self, None, QtCore.Qt.WindowStaysOnTopHint) app = QtGui.QApplication(sys.argv) mywindow = mymainwindow() mywindow.show() app.exec_()

PyQt and MVC-pattern

One of the first things you should do is use Qt4 designer to design your gui and use pyuic4 to generate your python GUI. This will be your view, you NEVER edit these python files by hand. Always make changes using designer, this ensures your View is separate from your model and control. For the … Read more

QListView/QListWidget with custom items and custom item widgets

I think you need to subclass QItemDelegate. QItemDelegate can be used to provide custom display features and editor widgets for item views based on QAbstractItemView subclasses. Using a delegate for this purpose allows the display and editing mechanisms to be customized and developed independently from the model and view. This code is taken from Qt’s … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)