[PyKDE] Problem: drawPushButton
Gerard Vermeulen
gvermeul at labs.polycnrs-gre.fr
Wed Jul 11 17:30:38 BST 2001
On Wednesday 11 July 2001 16:41, Grzegorz Zegartowski wrote:
> Gerard Vermeulen wrote:
> >Greg / Phil
> >
> >I looked in the qstyle.sip file and I quote:
> >
> >virtual void drawPushButton(QPushButton *,QPainter *) = 0;
> >virtual void drawPushButtonLabel(QPushButton *,QPainter *) = 0;
> >
> >Suppose it means that drawPushButton and drawPushButtonLabel
> >are pure virtual functions, meaning that you have to redefine
> >them in a derived class (this is a guess, read on).
> >
> >Greg, see themes.py in the examples directory how to do this :
> >def drawButton(self, p, x, y, w, h, g, sunken=FALSE, fill=None)
> >in the class NorwegianWoodStyle
> >
> >Gerard
>
> Should I really redefine drawPushButton() in Python?
> When you call: "style().drawPushButton()" in C++ program
> it works perfectly.
>
You are right, style() should return a derived class of QStyle
with a redefined drawPushButton().
Grepping through all *.sip files shows that drawPushButton has
been redefined.
Finally, I decided to add
print self.style().__class__.__name__
(self.style().className() is in the process of being fixed,
it should work in the CVS version, I believe)
I was expecting QMotifStyle() (running Linux)
Surprise: it was the generic QStyle().
So, I added a statement
app.setStyle(QPlatinumStyle())
in main()
That works!
Here, your revised code:
--
#!/usr/bin/env python
import sys
from qt import *
class MyPushButton(QPushButton):
""""""
def __init__(self, parent=None, name=None):
QPushButton.__init__(self, parent, name)
print self.style().__class__.__name__
def drawButton(self, painter):
self.style().drawPushButton(self, painter) #!error
self.drawButtonLabel(painter)
def main ():
"""main"""
app = QApplication(sys.argv)
app.setStyle(QPlatinumStyle())
mybtn = MyPushButton()
mybtn.setText("test")
app.setMainWidget(mybtn)
mybtn.show()
app.exec_loop()
if __name__ == '__main__':
main()
--
Gerard
More information about the PyQt
mailing list