Results 1 to 20 of 24

Thread: shape of push button

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Posts
    42
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Post shape of push button

    How to set the shape of push button /tool button. ? say to oval or round shape

    Thanks in advance

  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: shape of push button

    Subclass and reimplement the paint event.

  3. #3
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: shape of push button

    Another way is to write a new QStyle that styles only pushbuttons, and set set that style for the pushbuttons in question.

  4. #4
    Join Date
    May 2006
    Location
    Australia
    Posts
    53
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: shape of push button

    this is the way that I chose to subclass my buttons to get them to look like little green round "electrodes" in an electrode array

    Qt Code:
    1. void ElectrodeButton::paintEvent(QPaintEvent* event)
    2. {
    3. QPainter painter(this);
    4. painter.setRenderHint(QPainter::Antialiasing);
    5.  
    6. QRadialGradient grad(15, 15, 15, 0, 0);
    7.  
    8. grad.setColorAt(0.0, Qt::white);
    9. grad.setColorAt(0.1, Qt::green);
    10. grad.setColorAt(0.7, Qt::black);
    11. QBrush brush(grad);
    12. painter.setBrush(brush);
    13. painter.drawEllipse(2,2,20,20);
    14. }
    To copy to clipboard, switch view to plain text mode 

    ElectrodeButton is a subclass of QPushButton

  5. The following user says thank you to georgie for this useful post:

    MarkoSan (21st January 2008)

  6. #5
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Question Re: shape of push button

    Is it possible to adapt button shape dynamically according to loaded icon? What I want to achieve is when button icon is loaded, it's size and shape is reset to size and shape of overlaping icon. How do I do it?
    Qt 5.3 Opensource & Creator 3.1.2

  7. #6
    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: shape of push button

    It might be simplest to reimplement the paintEvent from the button. An alternative is to create a custom widget and provide an icon setting method that will also change the mask of the widget.

  8. #7
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: shape of push button

    Ok, but how do I extract icon shape? For size, I can use QIcon::actualSize?
    Qt 5.3 Opensource & Creator 3.1.2

  9. #8
    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: shape of push button


  10. The following user says thank you to wysota for this useful post:

    MarkoSan (22nd January 2008)

  11. #9
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: shape of push button

    Can you provide me with simple example, please?
    Qt 5.3 Opensource & Creator 3.1.2

  12. #10
    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: shape of push button

    An example of what? Calling createHeuristicMask?

  13. #11
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: shape of push button

    I did not get to step where I will use Calling createHeuristicMask yet. Right now, I have a big pixmap on disk (512x512) an when I set it in QPushButton it is so tiny it can be barely seen. I would like to resize it. How do I do that? I trided rescled, does not work. I tried to put some huge text near this pixmap in button, text is shown ok, pixmap is still tiny.

    Shit, I've mixed up threads. I've posted new thread regarding how to resize icon in subclassed qpushbutton. Can you move it?
    Qt 5.3 Opensource & Creator 3.1.2

  14. #12
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: shape of push button

    Quote Originally Posted by wysota View Post
    An example of what? Calling createHeuristicMask?
    Yes, how is heuristic mask used, becuase I have no idea how to adept push button shape to loaded pixmap.
    Qt 5.3 Opensource & Creator 3.1.2

Similar Threads

  1. push button fast activation
    By bhogasena in forum Qt Programming
    Replies: 1
    Last Post: 20th January 2009, 01:48
  2. Line edit and push button
    By dela in forum Newbie
    Replies: 1
    Last Post: 10th December 2008, 16:10
  3. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 22:25
  4. Push Button problem!!
    By Seema Rao in forum Qt Programming
    Replies: 1
    Last Post: 22nd April 2006, 16:31
  5. Push button double click
    By curtisw in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2006, 16:40

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.