PEP8 and PyQt, how to reconcile function capitalization?

In your shoes, I wouldn’t fight your framework, just like, as a general principle, I don’t fight City Hall;-). I happen to share your preference for lowercase-with-underscore function names as PEP 8 specifies, but when I’m programming in a framework that forces a different capitalization style, I resign myself to adopting that style too, since … Read more

How do I unit testing my GUI program with Python and PyQt?

There’s a good tutorial about using Python’s unit testing framework with QTest here (old link that does not work anymore. From the WayBackMachine, the page is displayed here). It isn’t about choosing one or the other. Instead, it’s about using them together. The purpose of QTest is only to simulate keystrokes, mouse clicks, and mouse … Read more

How to set QComboBox to item from item’s text in PyQt/PySide

Yes, there is QComboBox.findText, which will return the index of the matched item (or -1, if there isn’t one). By default, the search does exact, case-sensitive matching, but you can tweak the behaviour by passing some match-flags as the second argument. For example, to do case-insensitive matching: index = combo.findText(text, QtCore.Qt.MatchFixedString) if index >= 0: … Read more

How to programmatically make a horizontal line in Qt

A horizontal or vertical line is just a QFrame with some properties set. In C++, the code that is generated to create a line looks like this: line = new QFrame(w); line->setObjectName(QString::fromUtf8(“line”)); line->setGeometry(QRect(320, 150, 118, 3)); line->setFrameShape(QFrame::HLine); line->setFrameShadow(QFrame::Sunken);

PySide / PyQt detect if user trying to close window

Override the closeEvent method of QWidget in your main window. For example: class MainWindow(QWidget): # or QMainWindow … def closeEvent(self, event): # do stuff if can_exit: event.accept() # let the window close else: event.ignore() Another possibility is to use the QApplication‘s aboutToQuit signal like this: app = QApplication(sys.argv) app.aboutToQuit.connect(myExitHandler) # myExitHandler is a callable

What are good practices for avoiding crashes / hangs in PyQt?

General Programming Practices If you must use multi-threaded code, never-ever access the GUI from a non-GUI thread. Always instead send a message to the GUI thread by emitting a signal or some other thread-safe mechanism. Be careful with Model/View anything. TableView, TreeView, etc. They are difficult to program correctly, and any mistakes lead to untraceable … Read more

How to install PyQt4 in anaconda?

Updated version of @Alaaedeen’s answer. You can specify any part of the version of any package you want to install. This may cause other package versions to change. For example, if you don’t care about which specific version of PyQt4 you want, do: conda install pyqt=4 This would install the latest minor version and release … Read more