Page 1 of 2 12 LastLast
Results 1 to 20 of 34

Thread: Colored Buttons

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Colored Buttons

    "." instead of "->"

    because with the "->" I got a compiling error!

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: Colored Buttons

    Sure, I forgot you don't have a palette pointer

  3. #3
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Colored Buttons

    but the button is still gray!


  4. #4
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Colored Buttons

    arrrr it is green!!!

    I even dont know what my mistake was!!

    How can i use colors which are net predefined??

    Is it possible to enter anywhere a RGB code???

    Or something else?

    Best Regards, and thx

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: Colored Buttons

    Yes, you can construct a custom color with QColor( R, G, B ).
    Look at QColor.

    Regards

  6. #6
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Colored Buttons

    Quote Originally Posted by marcel View Post
    Yes, you can construct a custom color with QColor( R, G, B ).
    Look at QColor.

    Regards
    Another basic question from me: Is a QPushButton able to blink??

    For example: gray --> green --> gray --> green

    Best Regards!

  7. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: Colored Buttons

    Yes, if you use a QTimer, with let's say a 200ms delay. In the timerEvent slot you just switch the color from gray to green and then back.

    Regards

  8. #8
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Colored Buttons

    Quote Originally Posted by marcel View Post
    Yes, if you use a QTimer, with let's say a 200ms delay. In the timerEvent slot you just switch the color from gray to green and then back.

    Regards
    How can I find out which gray is the standard gray!!!! So that the Button looks like a button with no specific color??



    Best Regards?

  9. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: Colored Buttons

    A few notes:

    It is a good practice to get the palette from a widget, modify it, and set it back. Constructing a new palette object makes it use application's default palette which means losing any possible previous modifications to widget's palette:
    Qt Code:
    1. QPalette palette = widget->palette();
    2. palette.setColor(...);
    3. widget->setPalette(palette);
    To copy to clipboard, switch view to plain text mode 

    For a button, the correct color group is QPalette::Button:
    Qt Code:
    1. QPalette palette = button->palette();
    2. palette.setColor(QPalette::Button, Qt::green);
    3. button->setPalette(palette);
    To copy to clipboard, switch view to plain text mode 

    QWindowsXpStyle and QMacStyle use native theming engines which cause some palette modifications not to have any effect. Certain colors/brushes/whatever come from the underlying system. Style sheets is the solution to this problem. Follow the link and see the example of changing QPushButton's color there.
    J-P Nurmi

  10. #10
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Colored Buttons

    I got a runtime exception: Segmentation fault!

  11. #11
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Colored Buttons

    Now I tried a solution which causes no error and which seems to be working.

    My code is looking like that:

    I generate my own color out from a RGB code (also with alpha Parameter)

    Qt Code:
    1. QColor myColor;
    2. mycolor.setRgb(0, 150, 0, 255);
    3.  
    4. ...
    5. ...
    6. ...
    7.  
    8. myButton->setPalette(QPalette(Qcolor(myColor)));
    To copy to clipboard, switch view to plain text mode 


    It works fine!

    Best Regards,...

  12. The following user says thank you to Walsi for this useful post:

    fnmblot (25th April 2007)

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Colored Buttons

    Now try changing your application to a different style... Especially try the WindowsXP style.

  14. #13
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Colored Buttons

    give me a hint, please!

  15. #14
    Join Date
    Jun 2006
    Location
    Sweden
    Posts
    99
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    11
    Thanked 3 Times in 3 Posts

    Default Re: Colored Buttons

    Quote Originally Posted by Walsi View Post
    give me a hint, please!
    Qt Code:
    1. QColor oldButtonColor = pushButton->palette().color(QPalette::Button);
    To copy to clipboard, switch view to plain text mode 

  16. #15
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: Colored Buttons

    Walsi, which OS were you using ??
    I was using the same code to change the color of the button...
    setPalette(QPalette(QColor(m_color)));
    but i was using the button as Flat, and hence the color showed properly. I removed the flat property and it doesnt draw color on the button... i tried various roles like QPalette::Button , etc to change the color, but still no help

    Is it bec as Jpn suggested that native themes cause some effects not to have the desired effect ??

  17. #16
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Colored Buttons

    Quote Originally Posted by Walsi View Post
    Now I tried a solution which causes no error and which seems to be working.

    My code is looking like that:

    I generate my own color out from a RGB code (also with alpha Parameter)

    Qt Code:
    1. QColor myColor;
    2. mycolor.setRgb(0, 150, 0, 255);
    3.  
    4. ...
    5. ...
    6. ...
    7.  
    8. myButton->setPalette(QPalette(Qcolor(myColor)));
    To copy to clipboard, switch view to plain text mode 


    It works fine!

    Best Regards,...
    I use this code for changing the color of buttons and my operating system is KUBUNTU!
    I think version 6.10

  18. #17
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: Colored Buttons

    Did u try it on windows ??

  19. #18
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Colored Buttons

    What do you mean???

    Compiling this SourceCode on Windows?

    No I didn't try that.

    Best Regards

  20. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Colored Buttons

    If your code is meant to run on Windows too then I suggest you do that now and run it under WinXP.

  21. #20
    Join Date
    Mar 2007
    Location
    Vienna / Austria
    Posts
    54
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Re: Colored Buttons

    My code isn't suggested to run under WXP .... net yet??

    Will there be much problems with colored buttons on WXP?

Similar Threads

  1. Main window with custom buttons ?
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2006, 07:32
  2. array of radio buttons
    By amulya in forum Qt Programming
    Replies: 4
    Last Post: 5th October 2006, 13:59
  3. widget for text AND buttons
    By nongentesimus in forum Newbie
    Replies: 2
    Last Post: 16th June 2006, 14:43
  4. Replies: 9
    Last Post: 9th May 2006, 20:53
  5. How to get larger radio buttons on XP?
    By Ben.Hines in forum Qt Programming
    Replies: 9
    Last Post: 24th April 2006, 20:00

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
  •  
Qt is a trademark of The Qt Company.