PDA

View Full Version : Strange thing after override paintEvent function



Sheng
19th February 2009, 16:15
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

talk2amulya
19th February 2009, 16:25
would you mind sharing the code with us?

Sheng
19th February 2009, 16:34
would you mind sharing the code with us?



void myDialog::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing,true) ;
painter.setPen(QPen(Qt::black,1,Qt::SolidLine));
painter.drawLine(27,450,630,450);
painter.drawLine(30,50,30,453);
painter.drawLine(180,450,180,453);
painter.drawLine(330,450,330,453);
painter.drawLine(480,450,480,453);
painter.drawText(QPoint(570,470),tr("Time (Sec)"));
painter.drawText(QPoint(170,470),tr("75"));
painter.drawText(QPoint(470,470),tr("225"));
painter.drawText(QPoint(320,470),tr("150"));
painter.drawText(QPoint(10,40),tr("Force (lbs)"));
}


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.

aamer4yu
19th February 2009, 17:00
Had you promoted you dialog properly ?

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

Sheng
19th February 2009, 18:24
Had you promoted you dialog properly ?

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

I think it is crashed when constructor is called.



myDialog::myDialog()
{
setupUi(this);
updateTimer=new QTimer(this);
currentPoint=0;
connect(btnClose,SIGNAL(clicked()),this,SLOT(onClo se()));
connect(updateTimer,SIGNAL(timeout()),this,SLOT(up date()));
}


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

Sheng
20th February 2009, 14:18
I tried put a bitmap button in myDialog using designer, it also crashed.
Is it a bug of Qt? Any ideas?

aamer4yu
20th February 2009, 15:05
Can u post a code which reproduces the problem ?

Sheng
20th February 2009, 15:20
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.

talk2amulya
20th February 2009, 15:50
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

Sheng
20th February 2009, 16:44
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.