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
    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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.


  3. #3
    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, 13:46
  2. QMainWindow setCentralWidget from ui widget, Qt4
    By alan in forum Qt Programming
    Replies: 5
    Last Post: 13th May 2008, 13:00
  3. QMainWindow child of a QDialog
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2008, 07:16
  4. Replies: 3
    Last Post: 27th November 2006, 09:56
  5. QMainWindow not receiving QResizeEvent
    By brcain in forum Qt Programming
    Replies: 1
    Last Post: 28th September 2006, 06: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.