Results 1 to 10 of 10

Thread: Paint over a button.

  1. #1
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Paint over a button.

    Hi
    I have a frame and on that frame i have button , now i am trying to paint a arrow on that button but the drawn arrow hiden by button , so how i can draw arrow on the button like text display on the button.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Paint over a button.

    If you have the arrow image / icon, you can set it on to QPushButton (use QPushButton::setIcon()), along with the text

  3. #3
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Paint over a button.

    i do not have to use image so i am painting the arrow pls tell me how i can draw this shape on button.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Paint over a button.

    You can subclass QPushButton, and re implement paintEvent()

  5. #5
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Paint over a button.

    Ok is it not possible without subclassing QPushButton class?

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Paint over a button.

    It is possible. To suggest any further, I need to how you are painting the arrow?

  7. #7
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Paint over a button.

    IMO, without reimplementing paintEvent, any modifications will disappear when the button is repainted (for whatever reason) unless you use something like setIcon

  8. #8
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Paint over a button.

    Ok

    Qt Code:
    1. Light_frame::Light_frame(QWidget *parent) :
    2. QFrame(parent)
    3. {
    4. this->setStyleSheet("background-color:rgb(245, 245, 245)");
    5. button_on = new QPushButton(this);
    6. button_on->setText("ON");
    7. button_on->setGeometry(screenWidth/12 - screenWidth/20, screenHeight/4 + (screenHeight/2), screenWidth/11 ,screenHeight/11);
    8. button_on->setStyleSheet("QPushButton { color: rgb(131, 64, 0, 255); font-family: verdana, ms sans serif;font-size: 14pt; background-color: rgb(224, 224, 224,255); border-style: outset; border-width: 2px;border-radius: 10px; border-color: gray; } QPushButton:pressed { color:rgb(58, 129, 25); } ");
    9. ]
    To copy to clipboard, switch view to plain text mode 
    On this button's middle i am trying to do arrow as

    Qt Code:
    1. void Light_frame::paintEvent(QPaintEvent *event ){
    2. QPainter painter_arrow(this);
    3. painter_arrow.setPen(Qt::black);
    4. painter_arrow.setBrush(QColor(119, 65, 1));
    5.  
    6. QPointF point[4] = {
    7. QPointF(screenWidth/3 + screenWidth/8, screenHeight/3 + screenHeight/15),
    8. QPointF(screenWidth/3 + screenWidth/8 + 15, screenHeight/3 + screenHeight/15 + 25),
    9. QPointF(screenWidth/3 + screenWidth/8 + 30, screenHeight/3 + screenHeight/15),
    10. QPointF(screenWidth/3 + screenWidth/8 + 15, screenHeight/3 + screenHeight/15 + 5)
    11. };
    12. painter_arrow.drawPolygon(point, 4);
    13. }
    To copy to clipboard, switch view to plain text mode 

    but the drawn arrow overlapped by button.

  9. #9
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Paint over a button.

    So, you have QFrame sub-class where you paint a arrow, and add a QPushButton to the QFrame, then it is obvious that QPushButton will be over the arrow. You can paint the arrow on another frame, and this frame in to the existing frame after adding the button, this way arrow will be painted over the button.

    IMO, you will be complicating the situation by doing so, even though it is possible to paint arrow over button, you will run into problems later (as other poster suggested), like when you click the button it will not click, as arrow frame will eat away the mouse event, then you need to have another workaround.....

    Instead I would suggest set the arrow as an icon on to button, or look into other ways to do so (other than adding any widget/frame over push button)

  10. #10
    Join Date
    May 2011
    Posts
    120
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Paint over a button.

    Ok thank you.

Similar Threads

  1. Replies: 2
    Last Post: 26th April 2011, 11:44
  2. Changing text of button in no relation to button
    By Sabre Runner in forum Newbie
    Replies: 22
    Last Post: 23rd September 2010, 12:29
  3. Replies: 6
    Last Post: 21st August 2010, 21:09
  4. Replies: 1
    Last Post: 2nd August 2010, 05:40
  5. Paint XP radio button to pixmap
    By Ben.Hines in forum Qt Programming
    Replies: 2
    Last Post: 26th April 2006, 21:15

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.