pythonuser-interfaceqtpyqtownerdrawn

Custom/Owner draw control in PyQt?


I am learning PyQt and wonder if one can create custom/owner draw control like one show in the figure below:

alt text http://lh5.ggpht.com/_5XDoB4MglkY/SpoT51SXR1I/AAAAAAAAFcU/ZXjzmhRyDVA/s400/SearchBox.png

The search box has magnifier icon on its right border. Is this kind of thing possible with PyQt? Thanks!


Solution

  • If you only need to show an icon, an easy way is to use style-sheets:

    lineedit = QtGui.QLineEdit()    
    lineedit.setStyleSheet("""QLineEdit {
         background-image: url(:/images/magnifier.png);
         background-repeat: no-repeat;
         background-position: right;
         background-clip: padding;
         padding-right: 16px;
    }""")