Results 1 to 5 of 5

Thread: can you draw over a pushbutton?

  1. #1
    Join Date
    Feb 2006
    Posts
    29
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Windows

    Default can you draw over a pushbutton?

    hi,

    has anyone successfully, in its paintEvent, drawn over a QPushButton?

    Qt Code:
    1. void MyButton::paintEvent(QPaintEvent *Event)
    2. {
    3. QPainter painter(this);
    4. QPushButton::paintEvent(Event);
    5.  
    6. QRect buttonRect=rect();
    7. painter.setBrush(QBrush(Qt::red,Qt::SolidPattern));
    8. painter.drawRoundRect(buttonRect,20,20);
    9. painter.drawText(0,0,w,h, Qt::AlignRight | Qt::AlignVCenter,QString("Button"),&buttonRect);
    10. }
    To copy to clipboard, switch view to plain text mode 
    the code after the QPushButton:: paintEvent(Event) doesn't seem to do anything.

    now, take out line 4 and you can see that the code works. strange.

    anybody know how to fix this? stylesheets won't work for me in this case.

    thanks! -- lou

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

    Default Re: can you draw over a pushbutton?

    What happens if you initialize the painter after calling the base class version?

    Regards

  3. #3
    Join Date
    Feb 2006
    Posts
    29
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: can you draw over a pushbutton?

    Quote Originally Posted by marcel View Post
    What happens if you initialize the painter after calling the base class version?
    wow, that was it. this is a difference in qt4 from qt3 where i had no problems doing it this way.

    Thanks for that!
    lou

  4. #4
    Join Date
    Aug 2017
    Posts
    2
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Android Maemo/MeeGo

    Default Re: can you draw over a pushbutton?

    Hi,
    I am new to Qt. I am facing the problem. Can you please provide me your working code?

  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: can you draw over a pushbutton?

    Simply switch lines #3 and #4 in the OP's code.
    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.


Similar Threads

  1. why pushbutton moving??
    By Shuchi Agrawal in forum Qt Tools
    Replies: 7
    Last Post: 19th January 2007, 17:17
  2. How to resize window with pushbutton
    By kaydknight in forum Newbie
    Replies: 2
    Last Post: 13th January 2007, 12:17
  3. Using QGLWidget paint engine to draw regular widgtes?
    By high_flyer in forum Qt Programming
    Replies: 11
    Last Post: 9th October 2006, 12:06
  4. Drawing over content widgets? (overlay)
    By sertrem in forum Qt Programming
    Replies: 2
    Last Post: 17th January 2006, 22:18

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.