[PyQt] Re: QComboBox: display an item different from the chosen one
in the QListView
TP
paratribulations at free.fr
Sat Mar 28 08:23:13 GMT 2009
TP wrote:
> So I have tried to play with a lot of methods provided by QComboBox,
> without success (for example, "currentText", "setItemText", etc.).
For those that are interested, or Qt beginners like me: by examining Qt C++
source code, I have finally found a solution: I have specialized paintEvent
in my QComboBox derived class. For example, if I want to print "toutou" in
my QComboBox, I modify the QStyleOptionComboBox in paintEvent:
def paintEvent( self, qpaintevent ):
painter = QStylePainter( self )
painter.setPen( self.palette().color( QPalette.Text ) )
# draw the combobox frame, focusrect and selected etc.
opt = QStyleOptionComboBox()
self.initStyleOption( opt )
opt.currentText = QString( "toutou" ) # HERE!!!!!!
painter.drawComplexControl( QStyle.CC_ComboBox, opt )
# draw the icon and text
painter.drawControl( QStyle.CE_ComboBoxLabel, opt)
I have just translated paintEvent from C++ to Python, and add the
line "opt.currentText = QString( "toutou" )" to modify the content of the
QComboBox once one item has been chosen by the user.
Thanks
Julien
--
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"
"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)
More information about the PyQt
mailing list