Results 1 to 10 of 10

Thread: Strange thing after override paintEvent function

  1. #1
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Strange thing after override paintEvent function

    I override paintEvent function for a QDialog project. After that, in QDialog, I can not put label which load bitmap image any more. If I do so, there is "Segmentation error".
    Is that normal?
    Thanks

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange thing after override paintEvent function

    would you mind sharing the code with us?

  3. #3
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Strange thing after override paintEvent function

    Quote Originally Posted by talk2amulya View Post
    would you mind sharing the code with us?
    Qt Code:
    1. void myDialog::paintEvent(QPaintEvent *event)
    2. {
    3. QPainter painter(this);
    4. painter.setRenderHint(QPainter::Antialiasing,true);
    5. painter.setPen(QPen(Qt::black,1,Qt::SolidLine));
    6. painter.drawLine(27,450,630,450);
    7. painter.drawLine(30,50,30,453);
    8. painter.drawLine(180,450,180,453);
    9. painter.drawLine(330,450,330,453);
    10. painter.drawLine(480,450,480,453);
    11. painter.drawText(QPoint(570,470),tr("Time (Sec)"));
    12. painter.drawText(QPoint(170,470),tr("75"));
    13. painter.drawText(QPoint(470,470),tr("225"));
    14. painter.drawText(QPoint(320,470),tr("150"));
    15. painter.drawText(QPoint(10,40),tr("Force (lbs)"));
    16. }
    To copy to clipboard, switch view to plain text mode 

    and in Qt designer, I put a label and load a bitmap.
    After successfully compiled, when I run the application, it shows segmentation error.
    After I remove the label, it works fine.

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange thing after override paintEvent function

    Had you promoted you dialog properly ?

    Also try calling QDialog:aintEvent(event); before your code.

  5. #5
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Strange thing after override paintEvent function

    Quote Originally Posted by aamer4yu View Post
    Had you promoted you dialog properly ?

    Also try calling QDialog:aintEvent(event); before your code.
    I think it is crashed when constructor is called.

    Qt Code:
    1. myDialog::myDialog()
    2. {
    3. setupUi(this);
    4. updateTimer=new QTimer(this);
    5. currentPoint=0;
    6. connect(btnClose,SIGNAL(clicked()),this,SLOT(onClose()));
    7. connect(updateTimer,SIGNAL(timeout()),this,SLOT(update()));
    8. }
    To copy to clipboard, switch view to plain text mode 

    Now instead of adding image in designer, I load image in paintEvent function, it works fine.

  6. #6
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Strange thing after override paintEvent function

    I tried put a bitmap button in myDialog using designer, it also crashed.
    Is it a bug of Qt? Any ideas?

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange thing after override paintEvent function

    Can u post a code which reproduces the problem ?

  8. #8
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Strange thing after override paintEvent function

    Quote Originally Posted by aamer4yu View Post
    Can u post a code which reproduces the problem ?
    It basically same as putting label in Dialog. To me it seems after overriding paintEvent, you can not use designer to handle image anymore, I can only do it through overrided paintEvent function.

  9. #9
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange thing after override paintEvent function

    well, paintEvent() is the event called to draw the dialog after all..whenever u call update(), evth is erased and drawing starts from scratch..so if u r reimplementing it, u should do all the drawing there only..it makes sense..u can try it with smth other than QDialog, i believe same thing will happen

  10. #10
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Strange thing after override paintEvent function

    Quote Originally Posted by talk2amulya View Post
    well, paintEvent() is the event called to draw the dialog after all..whenever u call update(), evth is erased and drawing starts from scratch..so if u r reimplementing it, u should do all the drawing there only..it makes sense..u can try it with smth other than QDialog, i believe same thing will happen
    Thanks, that makes sense. Hopefully in the future the error will be pointed out during compilation instead of during run-time.

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  3. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

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.