Trying to learn PyQt with knowledge from Tkinter Trying to learn PyQt with knowledge from Tkinter tkinter tkinter

Trying to learn PyQt with knowledge from Tkinter


In Qt and PyQt events are called signals and you bind to them using slots (docs here). Generally speaking what you do define a slot with an @ decorator.

class WindowImpl (QtGui.QMainWindow, Ui_TremorMain, Ui_Graphs):  def __init__ (self, buffer, parent = None, configuration = None):    # do some initialisation here (not GUI setup however)  @QtCore.pyqtSlot(int, name="on_confSelectorCombo_currentIndexChanged")  def confChanged (self, newConf):    # do some stuff here to handle the event

The above would be triggered on the currentIndexChanged event of an object called confSelectorCombo. The setup of the confSelectorCombo is done in the GUI builder or Qt Creator as Nokia has decided to call it. This really is what you want to use to get started. There's tutorials here on using Qt Creator. Obviously you'll want to go through the docs and see what signals are emitted by which widgets.

As for the font stuff all I know is what it says on the docs:

If you have not set a font for your application then the default font on yourmachine will be used, and the default font can be different on differentmachines. On Windows the default Windows font is used, on X11 the one in qtrccan be used. If a default font can’t be found, then a font specified by Qtwill be used.

The QStyleSheet and QStyle act as proxies for changing the appearance of widgets (QStylesheet,QStyle).

As for making the application wait I found this

QTime dieTime = QTime::currentTime().addSecs(2);while( QTime::currentTime() < dieTime ):  QCoreApplication::processEvents(QEventLoop::AllEvents, 100);

There is also QThread.sleep() (docs), depending on what kind of an effect you want. Probably also worth looking at the threading support over at Qt docs

Overall in finding information about how to do stuff in PyQt I have found it surprisingly useful to look at the Qt documentation and then just writing the stuff in Python. 9 times out of 10 this works. On another note, it's probably also worth looking into PySide which is another python Qt library. I've haven't used myself before as it has been in the works previously but I noticed that they had released a 1.0.6 version.

UPDATEJust to reiterate Luke Woodward below, you can use QGraphicsScene and QGraphicsView to render stuff in an object oriented way. The QGraphicsScene doesn't actually render anything it just a scene graph, the QGraphicsView is then used to render the contents of the scene graph. For low level drawing there´s also QPainter - there's a basic drawing tutorial here. It's also worth looking at QGraphicsItem which is the base for all graphics items and

includes defining the item's geometry, collision detection, its painting     implementation and item interaction through its event handlers

docs here. The Context2D provides an HTML canvas (if I'm not mistaken through the use of WebKit). The canvas itself only has a changed slot, but any objects you place on the canvas will/can have more slots. There's a fairly complete looking tutorial on Context2D and Context2DCanvas here. For an explanation as to why so many different ways of rendering stuff, you'll have to ask someone else. My two cents is that is has something to do with the fact that Qt is supposed to work everywhere and Trolltech and later Nokia wanted to provide lots of choice. Luckily the docs are really good.