Results 1 to 6 of 6

Thread: QPushButton in QDockWidget loses stylesheet

  1. #1
    Join Date
    Aug 2008
    Location
    Cherry Hill, NJ USA
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QPushButton in QDockWidget loses stylesheet

    I have a QPushButton in a QDockWidget, and am setting the color of the push button using a simple stylesheet ("background-color:green").

    This works fine except that, when the QDockWidget containing the push button is undocked, the pushbutton reverts to its default color.

    I could subclass the QDockWidget, catch the topLevelChanged() signal, and change the push button's color to what it should be, but it seems like that shouldn't be necessary...

    Any ideas?

    Thanks,
    Martin

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QPushButton in QDockWidget loses stylesheet

    Quote Originally Posted by martinb0820 View Post
    I could subclass the QDockWidget, catch the topLevelChanged() signal, and change the push button's color to what it should be, but it seems like that shouldn't be necessary...
    This should really not be necessary, but with a quick test in designer I couldn't reproduce your problem. So could you make a minimal example reproducing your problem?

    Otherwise using the palette for simple background color change can solve your problem.

  3. #3
    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: QPushButton in QDockWidget loses stylesheet

    Quote Originally Posted by Lykurg View Post
    Otherwise using the palette for simple background color change can solve your problem.
    Unless you're using WindowsXP, Vista or Mac styles, of course.
    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.


  4. #4
    Join Date
    Aug 2008
    Location
    Cherry Hill, NJ USA
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: QPushButton in QDockWidget loses stylesheet

    Hi Lykurg,

    Thanks for trying it in Designer. I tried that after reading your reply, and it works in Designer's Form --> Preview, but doesn't work in the actual software...

    For what it's worth, the development environment is Visual Studio 2005 and the test system is XP. I'm using the commercial version of Qt 4.5.1.

    Could it be a bug in either Qt or XP?

    Martin

  5. #5
    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: QPushButton in QDockWidget loses stylesheet

    Could you provide a minimal compilable example reproducing the problem?
    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.


  6. #6
    Join Date
    Aug 2008
    Location
    Cherry Hill, NJ USA
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb Re: QPushButton in QDockWidget loses stylesheet

    I changed the stylesheet, and it works. Originally, one stylesheet specified the down and up appearance of the QPushButton. I changed the code to switch between two stylesheets, each of which specifies a different background-color, without specifying in the stylesheet whether the QPushButton is up or down. This works fine.

Similar Threads

  1. QPushButton loses shortcut
    By Cruz in forum Qt Programming
    Replies: 1
    Last Post: 22nd February 2009, 06:21
  2. Qpushbutton
    By iamhere in forum Qt Programming
    Replies: 5
    Last Post: 15th October 2008, 04:40
  3. Replies: 3
    Last Post: 28th January 2007, 17:24

Tags for this Thread

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.