Results 1 to 13 of 13

Thread: paintEvent not getting called with QMainWindow

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2009
    Posts
    63
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: paintEvent not getting called with QMainWindow

    Yes, spirit, you're pretty much right. Being relatively new to Qt, I am discovering its quirks. I guess by design the paintEvent will not get called in my case of the QMainWindow. I understand that my event filter should capture events from the central widget, but what type of code would I need in my eventFilter() method to ensure this works, i.e. gets painted?

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

    Default Re: paintEvent not getting called with QMainWindow

    you should do like this
    Qt Code:
    1. bool MyMainWindow::eventFilter(QObject *o, QEvent *e)
    2. {
    3. if (o == centralWidget() && e->type() == QEvent::Paint) {
    4. //paint on central widget
    5. ...
    6. }
    7. return QMainWindow::eventFilter(o, e);
    8. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: paintEvent not getting called with QMainWindow

    Quote Originally Posted by DiamonDogX View Post
    I guess by design the paintEvent will not get called in my case of the QMainWindow.
    It is called. You just don't see its result because something else paints over it.
    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.


  4. #4
    Join Date
    Dec 2009
    Posts
    29
    Thanks
    2
    Thanked 3 Times in 3 Posts

    Default Re: paintEvent not getting called with QMainWindow

    How can you say its called or not. I am in the same situation and I simply put a breakpoint in the function and the program never reached the breakpoint therefor it is not getting called.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: paintEvent not getting called with QMainWindow

    You just check if it is called:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class MyWindow : public QMainWindow {
    4. public:
    5. MyWindow(){}
    6. protected:
    7. void paintEvent(QPaintEvent *pe){
    8. qDebug() << Q_FUNC_INFO;
    9. QMainWindow::paintEvent(pe);
    10. }
    11. };
    12.  
    13. int main(int argc, char **argv){
    14. QApplication app(argc, argv);
    15. MyWindow mw;
    16. mw.show();
    17. return app.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 

    In this example it is called.
    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.


  6. #6
    Join Date
    Dec 2009
    Posts
    29
    Thanks
    2
    Thanked 3 Times in 3 Posts

    Default Re: paintEvent not getting called with QMainWindow

    In my case, this was happening with a QFrame. Here is the solution if anyone ever needs it:

    Qt Code:
    1. rgbFrame::rgbFrame(QWidget * parent, Qt::WindowFlags f): QFrame(parent, f)
    2. {
    3. installEventFilter(this);
    4. }
    5.  
    6. void rgbFrame::paintEvent(QPaintEvent *e)
    7. {
    8. QFrame::paintEvent(e); // pass event to base class
    9. }
    10.  
    11.  
    12. bool rgbFrame::eventFilter(QObject *o, QEvent *e)
    13. {
    14. if (e->type() == QEvent::Paint) {
    15. paintEvent((QPaintEvent *)e);
    16. }
    17. return QFrame::eventFilter(o, e);
    18. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 1
    Last Post: 7th August 2008, 14:46
  2. QMainWindow setCentralWidget from ui widget, Qt4
    By alan in forum Qt Programming
    Replies: 5
    Last Post: 13th May 2008, 14:00
  3. QMainWindow child of a QDialog
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2008, 08:16
  4. Replies: 3
    Last Post: 27th November 2006, 10:56
  5. QMainWindow not receiving QResizeEvent
    By brcain in forum Qt Programming
    Replies: 1
    Last Post: 28th September 2006, 07:11

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.