Why does QWidget always require update screen twice from hidden to showing.
-
Hi All:
I tried to program a test code as following, and run it.
After application running, I press alt+tab to swap the QT application window.
I see the w(MainWindow ) always receive 2 QEvent::Paint evnets.
I have no idea for that symptom, does any one know what happen is it?
Does the symptom impact QT GUI display performance.
Thanks for viewing.class evtFilter:public QWidget
{
public:
bool eventFilter(QObject * obj_p, QEvent * e_p)
{// qDebug() << obj_p; if(e_p->type() == 12) { qDebug() << e_p->type(); } return false; }
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
evtFilter filter;
w.installEventFilter(&filter);
w.setGeometry(0, 0, 200, 200);
w.show();return a.exec();
}
-
Hi,
What is MainWindow ? What does it contain ?
Your filter is seeing two events however you don't check who got the events. That's what the first argument is for. Identify who go it.
You should also state which OS you are running as well as Qt version.
-
Hi SGait:
Thanks for your response :).MainWindow is created by QT creator, it just inherit QWidget and the detail define as below.
Due to MainWindow::paintEvent(QPaintEvent *p) is invoked twice when window swapping.
so I install a event filter in MainWindow to double check the event forwarding.
And it is 2 paint events when window swapping really.And the running environment as following
OS: Windows 7
Toolchain : MinGw 4.9.32
QT version: 4.7.3namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();private:
Ui::MainWindow *ui;
void paintEvent(QPaintEvent *p);
};MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::paintEvent(QPaintEvent *p)
{
qDebug() << "11111111111";
}class evtFilter:public QWidget
{
public:
bool eventFilter(QObject * obj_p, QEvent * e_p)
{// qDebug() << obj_p;
if(e_p->type() == 12)
{
qDebug() << e_p->type();
}
return false;
}
};int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
evtFilter filter;
w.installEventFilter(&filter);
w.setGeometry(0, 0, 200, 200);
w.show();return a.exec();
} -
Qt 4.7.3 ? Why that old outdated version ?
-
In that case, please consider updating to 4.8.7.