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

Thread: VistaGlassButton widget for Qt 4

  1. #1
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default VistaGlassButton widget for Qt 4

    For a current project I subclassed a QPushButton and re-painted it to look like a Vista Aero glass button. You use it like a normal QPushButton, except there are two public methods - setColor(QColor color) and setShadow(QColor shadow). Color is the red area in the image below, Shadow is the black center. Anyway, I thought it might come in handy for people wanting a look like this or for anyone wondering how to go about redrawing a widget:



    You can download the class here:

    http://www.mediafire.com/?e2v82uujtin

    Enjoy!


    *I haven't tested this class extensively, but it works okay for normal-looking buttons. If you start doing crazy things with it, however, it might go wonky. Feel free to modify/improve to your heart's content...
    Last edited by JimDaniel; 13th February 2008 at 06:00.

  2. The following 3 users say thank you to JimDaniel for this useful post:

    ComaWhite (15th March 2008), giowck (29th May 2010), THRESHE (10th March 2008)

  3. #2
    Join Date
    Mar 2006
    Posts
    48
    Thanks
    5
    Thanked 4 Times in 3 Posts

    Default Re: VistaGlassButton widget for Qt 4

    look great, but if u add border for button it will be awesome
    waiting for new vista style widgets...

  4. #3
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: VistaGlassButton widget for Qt 4

    Thanks, there is a slight border now but you can barely see it. I will make it a bit wider to match the style.

    Yes, several things are not quite right that I intend to fix. For one thing you can't an icon to this button as of now, and also it does not use the buttons font info to generate the text. And I need to add a public method to set the transparency of the button. But I plan to upload any changes I make here, so feel free to make any other suggestions.

  5. #4
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default UPDATED [Qt AeroButton]

    I can't seem to stop fooling with this button class. Today I added most of the features I felt were missing and renamed it AeroButton. It now functions exactly like a QPushButton except you can't yet display both icon and text. It provides an extremely simple yet flexible API:

    setColor(QColor color);
    setHighlight(QColor highlight);
    setShadow(QColor shadow);

    *shadow is not the depressed state color, which is calculated automatically, but the center gradient, the black area in the image below.

    setRoundess(int roundess);
    setOpacity(qreal opacity);



    I hope someone is able to use it. Let me know what you think and what I can do to improve...

    Download:
    AeroButton.zip
    Last edited by JimDaniel; 14th February 2008 at 06:03.

  6. The following 2 users say thank you to JimDaniel for this useful post:

    MorrisLiang (15th May 2010), vasanth (12th May 2008)

  7. #5
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: UPDATED [Qt AeroButton]

    License, copyright ...? GPL? LGPL? BSD? Who is the author?

  8. #6
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: UPDATED [Qt AeroButton]

    Quote Originally Posted by elcuco View Post
    License, copyright ...? GPL? LGPL? BSD? Who is the author?
    I'm the author. No license, no copyright, you can do with it whatever you like...

  9. #7
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: VistaGlassButton widget for Qt 4

    Then put on the sources "Public domain". Otherwise, I am not authorized to use it.

    THANKS!!!

  10. #8
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Public Domain

    Public Domain Version:
    PD_AeroButton.zip

    Using the code, I noticed the black outline does not look exactly right the more round you make the button. You have to tweak it to get it to look just right. Honestly, the formula for drawing the outline seems a bit clunky. If anyone uses the code and sees how drawing the outline can be improved, please let me know...

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

    Default Re: VistaGlassButton widget for Qt 4

    Psst! Feel free to put it on our wiki if you want to. There's a special [WIKI]custom widgets[/WIKI] page which didn't yet reach the popularity I hoped.
    J-P Nurmi

  12. #10
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Added Wiki page entry

    Last edited by JimDaniel; 14th February 2008 at 21:58.

  13. #11
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: VistaGlassButton widget for Qt 4

    Looks awesome !!
    And thank you for sharing the code with us
    We can't solve problems by using the same kind of thinking we used when we created them

  14. #12
    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: UPDATED [Qt AeroButton]

    Isnt't the button look achievable using stylesheets without any subclassing? A simple border+border-radius+linear gradient as a background.

    One way or the other I suggest you use the palette (QWidget::palette) instead of having methods for setting custom colours. This way your widget will become easily customizable and stylable out of the box.

  15. #13
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: UPDATED [Qt AeroButton]

    Yeah, as long as a style sheet can handle the opacity properties and the roundness of the button, I'm sure you could. There are a couple of layers involved, with different opacities. Can a style sheet handle this well? I'm not too familiar with css. But from a design perspective, doesn't it seem dirty to clutter the code with all those style sheet properties. Wouldn't it be much cleaner to just have a class to use when you want this style of button?

    As far as using the widget's palette, I'm not sure what you mean. I'm still quite the beginner with Qt. I just did it the best way I knew how. So if you can elaborate a bit more, I would be grateful.

    Also, while we're discussing what's wrong with my class, one thing that troubles me is that the correct signals for a push button are no longer emitted. I call click() myself in the mousePressEvent() override. Is there an easy way to let the default signals be emitted?

  16. #14
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: UPDATED [Qt AeroButton]

    Quote Originally Posted by JimDaniel View Post
    As far as using the widget's palette, I'm not sure what you mean. I'm still quite the beginner with Qt. I just did it the best way I knew how. So if you can elaborate a bit more, I would be grateful.
    Have a look at QPalette.

    Quote Originally Posted by JimDaniel View Post
    Also, while we're discussing what's wrong with my class, one thing that troubles me is that the correct signals for a push button are no longer emitted. I call click() myself in the mousePressEvent() override. Is there an easy way to let the default signals be emitted?
    You just have to "forward" the events, e.g. :
    Qt Code:
    1. void AeroButton::mousPressEvent(QMouseEVent *e)
    2. {
    3. // your code here...
    4.  
    5. QPushButton::mousePressEvent(e);
    6. }
    To copy to clipboard, switch view to plain text mode 
    Current Qt projects : QCodeEdit, RotiDeCode

  17. The following user says thank you to fullmetalcoder for this useful post:

    JimDaniel (21st February 2008)

  18. #15
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: UPDATED [Qt AeroButton]

    Awesome, thanks fmc!

  19. #16
    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: UPDATED [Qt AeroButton]

    BTW. "click()" should be emitted in the release event, not press event.

    As for a separate class - what exactly the button is meant for? Is it a regular Vista push button? If so, you should get the looks out of the box when using an appropriate widget style.
    Last edited by wysota; 22nd February 2008 at 07:27.

  20. #17
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: UPDATED [Qt AeroButton]

    Quote Originally Posted by wysota View Post
    As for a separate class - what exactly the button is meant for? Is it a regular Vista push button? If so, you should get the looks out of the box when using an appropriate widget style.
    Wild guess : hard-coded styling of the application, just like the window decorations related thread we had some time ago... Or could also be an attempt to bring Vista look'n'feel to other platforms (but this ought to be done through a QStyle subclass).
    Current Qt projects : QCodeEdit, RotiDeCode

  21. #18
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: UPDATED [Qt AeroButton]

    No, I call it a Vista glass button, but really the glassy look is just a popular visual style nowadays, it just happens to be popularly used in Vista so I called it that.

    Our project needed a button like this and I was experimenting with the paintEvent(). That's all really.

    You gurus might have forgotten, but when you first start using Qt, how things work is not always as self-explainatory as it seems. I would have loved to have examples like this when I first started. Maybe there are better ways to do what I did, but this method seems perfectly valid for our intentions.

  22. #19
    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: UPDATED [Qt AeroButton]

    Quote Originally Posted by JimDaniel View Post
    No, I call it a Vista glass button, but really the glassy look is just a popular visual style nowadays, it just happens to be popularly used in Vista so I called it that.
    If you use that style then yourr application buttons should automatically take the same look without any custom classes or stylesheets. Of course on Vista only, but that's quite natural.

    You gurus might have forgotten, but when you first start using Qt, how things work is not always as self-explainatory as it seems. I would have loved to have examples like this when I first started. Maybe there are better ways to do what I did, but this method seems perfectly valid for our intentions.
    Don't worry, we didn't say you have done something bad. I merely asked for the purpose of having the class. If it is a regular button on Vista then I suggest not using it and instead make your application adopt the look and feel from the operating system itself. That's a "Qt way" of doing things. If you are unable to have the buttons you need using regular methods, then feel free to use any custom classes you want - just beware your application might look strange or even stop working if someone runs it on a different system configuration.

  23. #20
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: UPDATED [Qt AeroButton]

    That looks awesome *drools*

Similar Threads

  1. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  2. Custom widget
    By zorro68 in forum Qt Programming
    Replies: 7
    Last Post: 28th January 2008, 14:06
  3. Replies: 3
    Last Post: 17th October 2007, 12:52
  4. transparent background of the main widget
    By nagpalma in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2007, 17:52
  5. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 14:16

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.