QStackedWidget - paintevent of widget not getting called
Hi,
Please consider the below codes:
File : mainwindow.cpp
Code:
mainwindow::mainwindow()
{
men = new menu1(this);
connect(quran1, SIGNAL(clicked()), this, SLOT(qopen()));
qs->addWidget(men);
qs->setCurrentIndex(0);
show();
}
File : men.cpp
Code:
{
resize(880, 580);
}
void menu1
::paintEvent(QPaintEvent *) // THIS JUST DRAWS A GREEN CURVE {
painter.
setRenderHint(QPainter::Antialiasing,
true);
path.moveTo(qrand() % 80, qrand() % 320);
path.cubicTo(200, 200, 320, 80, 480, 320);
painter.
setPen(QPen(Qt
::green,
8));
painter.drawPath(path);
}
The problem is, whenever I run the above code, in the output, all I get is the pushbutton but not the green curve which is in the paintevent of menu1.
HOWEVER,
When I remove the QStackedWidget from mainwindow.cpp as shown below, I get both the pushbutton AND the green curve.
Code:
mainwindow::mainwindow()
{
men = new menu1(this);
connect(quran1, SIGNAL(clicked()), this, SLOT(qopen()));
show();
}
What is the problem with QStackedWidget? How can I get both the pushbutton and the curve to appear with the first example of mainwindow?
Regards.
Re: QStackedWidget - paintevent of widget not getting called
Try giving the stacked widget a large enough size explicitly.
Re: QStackedWidget - paintevent of widget not getting called
Quote:
Originally Posted by
high_flyer
Try giving the stacked widget a large enough size explicitly.
Yeah, your trick worked perfectly. Thanks.