[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyQt] Re: QComboBox: display an item different from the chosen one
From:       TP <paratribulations () free ! fr>
Date:       2009-03-28 8:23:13
Message-ID: hc31a6-175.ln1 () rama ! fbx ! proxad ! net
[Download RAW message or body]

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)

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic