Results 1 to 10 of 10

Thread: QPushButton - Only show the Icon

  1. #1
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QPushButton - Only show the Icon

    Hi
    I checked the "flat" property on a QPushButton containing a Icon.
    Whe i press the button the original rectangular shape shows again?
    How do i disable this?

    Thanks

  2. #2
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPushButton - Only show the Icon

    I don't think this is possible, as the user needs some response that "something" is happening when he presses the flat button.
    Otherwise the button could be a QLabel which normally never changes its shape. But of course a label has no clicked() signal.

  3. #3
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton - Only show the Icon

    I'm using 2 diferent Pixmaps for that.
    One for pressed and one for released.
    That's why i want the original sape to go away.

  4. #4
    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 - Only show the Icon

    Then subclass QPushButton and write your own print() method. It's not that difficult.

  5. #5
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton - Only show the Icon

    Don't want to sound lazzy but ... is there any example for me to look in for how to write that print method ... a place to start

  6. #6
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPushButton - Only show the Icon

    Qt source code . There are billions of paint methods implemented. Start at QPushButton:: paint().

  7. The following user says thank you to Boron for this useful post:

    graciano (19th September 2009)

  8. #7
    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 - Only show the Icon

    Quote Originally Posted by Boron View Post
    Qt source code . There are billions of paint methods implemented. Start at QPushButton:: paint().
    Ah, I'm going crazy. I cant keep that in mind! It's not print and neither it's paint: It's QWidget::paintEvent(QPaintEvent *event)!

    Qt Code:
    1. class MyButton : public QPushButton
    2. {
    3. //...
    4. void setImages(QImage normal, QImage pressed /*...*/);
    5. protected:
    6. void paintEvent(QPaintEvent *event);
    7. private:
    8. QImage m_normal;//...
    9. };
    10.  
    11. void MyButton::paintEvent(QPaintEvent *event)
    12. {
    13. QPainter painter(this);
    14. // do your painting here
    15. }
    To copy to clipboard, switch view to plain text mode 

  9. The following user says thank you to Lykurg for this useful post:

    graciano (19th September 2009)

  10. #8
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton - Only show the Icon

    I see ... thanks for the tips.
    I will try this way.

  11. #9
    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 - Only show the Icon

    It should be possible to obtain the same effect purely by using stylesheets too.
    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.


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

    graciano (19th September 2009)

  13. #10
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton - Only show the Icon

    Yess ... that's what i did for not making the solution "too complex" for the moment.
    this did the job:
    Qt Code:
    1. w.setStyleSheet("QPushButton {border-style: outset; border-width: 0px;}");
    To copy to clipboard, switch view to plain text mode 

    Thanks all

Similar Threads

  1. Problems with QPushButton displaying an icon
    By John82 in forum Qt Programming
    Replies: 9
    Last Post: 2nd July 2009, 17:42
  2. Stretching Icon in QPushButton
    By dsandber in forum Qt Tools
    Replies: 1
    Last Post: 6th October 2007, 16:51
  3. QSystemTrayIcon doesn't show icon ?
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 25th January 2007, 19:17
  4. QPushbutton Flat property and icon appearance.
    By darpan in forum Qt Programming
    Replies: 1
    Last Post: 4th November 2006, 08:30
  5. WYSIWYG html, Window show png icon mac no!
    By patrik08 in forum Qt Programming
    Replies: 10
    Last Post: 25th May 2006, 12:01

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.