PyQt Tips and Tricks

(Identifying the Sender of a Signal)
(Web Resources)
Line 55: Line 55:
* [ Maemo Version of the QT Documentation]
* [ Maemo Version of the QT Documentation]
* [ Maemo-specific platform notes]
* [ Maemo-specific platform notes]
* [ PyQt4 Examples]

Revision as of 15:00, 16 June 2010

With Meego there is a lot of interest in developing applications in Qt rather than GTK. This page spawned from a discussion thread.


Tips and Tricks

Identifying the Sender of a Signal

There are two main approaches for this. The first is to wrap the slot with a lambda to pass in any additional arguments

def notifyMe(foo)
  print foo
f = QPushButton("Click me!")
x = lambda: notifyMe("they call him tim")
self.connect(f, SIGNAL("clicked()"), x)


The second and more general solution is to use the QSignalMapper[2]

Learning to use Qt CSS

Much like web development, CSS is also available within Qt. There's a list of examples that can be tried out just using Qt Designer. If you're using custom CSS, using palette() in your CSS definitions will allow you to use colors that the theme already knows about. As an example, this is an easy way to get the default blue color on your buttons when you want that color.

Depending on your needs, there's a number of built-in icons that are available for use.[3]

Style sheets and the native QMaemo5Style do not mix very well, since Maemo 5 lays out and draws some widgets very differently (e.g. QRadioButton). We recommend using local style sheets on specific widgets only, instead of setting one via QApplication::setStyleSheet().[4]

Stacked Windows

 class showWindowQtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_main_window()


Example Applications

  • ncalc
  • nclock
  • maesynth
  • maelophone
  • healthcheck
  • Gonvert (1.0+)

Web Resources