Results 1 to 3 of 3

Thread: calling paintEvent() of the super class

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    383
    Thanks
    99
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default calling paintEvent() of the super class

    Hi!

    So I have overridden paintEvent() of a QFrame and I can paint what I want, but now I can do ONLY what I want. Things like background color, borders and corners are missing. Don't I have to somehow call super.paintEvent() first? How do I do that?

    Thanks
    Cruz

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: calling paintEvent() of the super class

    did you try something like this?
    Qt Code:
    1. void MyFrame::paintEvent(QPaintEvent *event)
    2. {
    3. QFrame::paintEvent(event);
    4. //then you can draw what you need
    5. ....
    6. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Cruz (16th January 2009), ihope (11th August 2009)

  4. #3
    Join Date
    Mar 2021
    Posts
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: calling paintEvent() of the super class

    Quote Originally Posted by Cruz View Post
    Hi!

    So I have overridden paintEvent() of a QFrame and I can paint what I want, but now I can do ONLY what I want. Things like background color, borders and corners are missing. Don't I have to somehow call super.paintEvent() first? How do I do that?

    Thanks
    Cruz
    You have to draw the primitive element and then you draw what you want.
    Qt Code:
    1. opt.init(this);
    2. QPainter p(this);
    3. style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  2. function 'connect' always look super class for slots.
    By Intaek Lim in forum Qt Programming
    Replies: 7
    Last Post: 12th March 2007, 13:38
  3. Problems calling C function in C++/Qt class
    By Rayven in forum General Programming
    Replies: 2
    Last Post: 2nd June 2006, 21:32

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.