Results 1 to 2 of 2

Thread: stylesheets and drawControl(CE_PushButton)

  1. #1
    Join Date
    Mar 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default stylesheets and drawControl(CE_PushButton)

    I am struggling with a qt behavior which is either a bug or a feature.
    I wrote a little pyqt program for demonstration.

    python Code:
    1. import PyQt4.QtGui as gui
    2. import sys
    3.  
    4. class TestButton1(gui.QPushButton):
    5. def paintEvent(self, event):
    6. painter = gui.QStylePainter(self)
    7. option = gui.QStyleOptionButton()
    8. self.initStyleOption(option)
    9. painter.drawControl(gui.QStyle.CE_PushButton, option)
    10.  
    11.  
    12. class TestButton2(gui.QPushButton):
    13. def paintEvent(self, event):
    14. painter = gui.QStylePainter(self)
    15. option = gui.QStyleOptionButton()
    16. self.initStyleOption(option)
    17. style = self.style()
    18. style.drawControl(gui.QStyle.CE_PushButton, option, painter)
    19.  
    20.  
    21. if __name__ == "__main__":
    22. app = gui.QApplication(sys.argv)
    23. app.setStyleSheet("QPushButton {background-color: #ff0000;}")
    24.  
    25. frame = gui.QFrame()
    26. frame.setLayout(gui.QVBoxLayout())
    27. frame.layout().addWidget(TestButton1(text="test1"))
    28. frame.layout().addWidget(TestButton2(text="test2"))
    29. frame.show()
    30.  
    31. app.exec_()
    To copy to clipboard, switch view to plain text mode 

    The program shows a small window with two push buttons. The only difference between the buttons is the call of drawControl.

    In linux both buttons are rendered with a red background.
    In windows the "test1" is rendered red, but "test2" is rendered with the default colour.

    Originally I wanted to "steal" the style of a QPushButton to draw it inside an ItemDelegator.
    Last edited by wysota; 20th March 2011 at 22:20. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: stylesheets and drawControl(CE_PushButton)

    I would say this is caused by the fact that the call to style (and not to the painter) omits the global stylesheet or even all stylesheets. Stylesheets are implemented as a sort of style proxy. Since you are calling the style directly, the call is probably not "proxied" through the button's style settings. It's an interesting "feature" although it's just a guess, I may be wrong. Try passing "self" as the last argument to drawControl, it might help by informing the style about the widget being painted.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Where to put my stylesheets?
    By martinn in forum Qt Programming
    Replies: 3
    Last Post: 2nd February 2010, 15:28
  2. Stylesheets
    By FuryCradle in forum Newbie
    Replies: 2
    Last Post: 26th September 2009, 21:34
  3. CE_PushButton
    By panduro in forum Newbie
    Replies: 2
    Last Post: 19th June 2008, 08:41
  4. stylesheets with RGB
    By tommy in forum Qt Programming
    Replies: 4
    Last Post: 13th December 2007, 01:02
  5. Stylesheeting and QStyle::drawControl() - possible?
    By dimuz in forum Qt Programming
    Replies: 2
    Last Post: 22nd October 2007, 08:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.