Blinking during program start
-
Hello everyone,
I have problem with blinking while my program starts.
My program starts with login form. After success authorization I need to create a widget which include QTabWidget.
But when the next tab is creating I see that it is showing and closing during several milliseconds. After all tabs have created, finally appears my QTabWidget with all this tabs.
Maybe my question is stupid, but how hide all this blinking during my application is starting? Maybe I can some way stop paint event to moment when application will have totally created?Thanks for your response)
-
Hi,
Can you show us your code? How do you create your tab widget?
-
hello,
thanks for response. Something like that:
@
myWidget::myWidget(QString login_name,QString role_id,QString code_id) {
QTabWidget* tab = new QTabWidget;
QList<group*> lst_group;
QSqlQuery sqlQuery;
sqlQuery.exec("select group_name from current_group");
while(sqlQuery.next())
{
lst_group.push_front(new group(sqlQuery.value(0).toString(), login_name, role_id, code_id));
tab->addTab(lst_group.first(), sqlQuery.value(0).toString());
}setCentralWidget(tab);
show();
}
@ -
Hi,
So it seems that this method is somehow ripped from a QMainWindow subclass, right?
This group is a subclass of QWidget (probably a QGroupBox), right?
I don't see how you could see any tabs dis- and reappearing. The tabs are being created and only thereafter the QTabWidget is being added to the main window and the main window is shown.
If there is a show() in another method that occurs before this method (myWidget) is called, the QMainWindow might already be visible. But there is no way how the QTabWidget could be displayed while the tabs are not yet generated, as it is added to the QmainWindow only after the tabs' creation.
Usually, a widget itself has no influence on its own appearance within a QTabWidget (including its tab's title). If the QWidget is deleted it might eventually deregister from the QTabWidget, but that should be pretty much the only influence it should have on the QTabWidget.
I considered for a moment, that the QTabWidget' tab title might be linking with the QGroupBox's title (as the concept is somewhat similar). Then the widget might change its tab's title (which it normally couldn't). But the docu doesn't state anything like that.
Two things occurred to me while reading that code, however non of them explains the behavior you described:
- Should there be parenthesis at the end of this line:
@ QTabWidget* tab = new QTabWidget;@
like:
@ QTabWidget* tab = new QTabWidget(); @
- I never actually set the centralWidget. I always set a layout for it and added my widgets to that. I figured using a subclass of QWidget (rather than a QWidget itself) might cause problems. But this should be stated in the "docu":http://qt-project.org/doc/qt-4.8/qmainwindow.html#setCentralWidget. Since, it doesn't have any disclaimers (like for instance: "Don't ever use a QWidget subclass as a central widget!") I don't think it should be a problem.
Sorry, I don't have a solution. Only some thoughts.
Best
Soraltan
- Should there be parenthesis at the end of this line:
-
[quote author="Romaniy" date="1401692552"]
@
lst_group.push_front(new group(sqlQuery.value(0).toString(), login_name, role_id, code_id));
tab->addTab(lst_group.first(), sqlQuery.value(0).toString());
@
[/quote]Remove show() from your group constructor. If you show it and then add it to the tab widget, it will appear and then disappear -- that's probably why you have blinking.[quote author="Soraltan" date="1401701132"]
- Should there be parenthesis at the end of this line:
@ QTabWidget* tab = new QTabWidget;@
like:
@ QTabWidget* tab = new QTabWidget(); @
[/quote]No need. Both of those use the default constructor. - Should there be parenthesis at the end of this line:
-
bq. No need. Both of those use the default constructor.
Hmm, learned something new today. Nice. Thanks :-)
-
Hello everybody,
thanks for your response.
bq. Remove show() from your group constructor. If you show it and then add it to the tab widget, it will appear and then disappear — that’s probably why you have blinking.
I don’t use show() in group constructor. I have checked it several time to be sure, but no show() method there. So, I don't understand where I could make mistake.
-
I think mistake could be in the another part of my program, but i can't explain that.
So, my application start working with login class. In this class I specified some widget for pass and login.
After user have put his/her login and password, I check it validity and if they correct I'll hide my login windows and will create myWidget new object inside login class. After my login windows have disappeared(I just hide it, because this class create connection to database and hold it), I see that every new tab appear and disappear for a little period of time. After that I see myWidget application. I use method show only two time: first - in login object(hide before myWidget constructor begin working), second - when myWidget have already created.Maybe mistake appear in login class?
-
[quote author="Romaniy" date="1402004179"]I don’t use show() in group constructor. I have checked it several time to be sure, but no show() method there.[/quote]Ah, my guess was wrong. Sorry!
Can you show us your group constructor?
Also, what happens if you comment out this line and then run your program?:
@
tab->addTab(lst_group.first(), sqlQuery.value(0).toString());
@[quote author="Romaniy" date="1401692552"]
@
myWidget::myWidget(QString login_name,QString role_id,QString code_id) {
QTabWidget* tab = new QTabWidget;
QList<group*> lst_group;
QSqlQuery sqlQuery;
sqlQuery.exec("select group_name from current_group");
while(sqlQuery.next())
{
lst_group.push_front(new group(sqlQuery.value(0).toString(), login_name, role_id, code_id));
tab->addTab(lst_group.first(), sqlQuery.value(0).toString());
}setCentralWidget(tab);
show();
}
@
[/quote]Some questions:Why do you need lst_group ?
How many classes access your SQL database?
-
Hello, JKSH,
you was right. I had the next string in group constructor:
@p_frame->setVisible(true);@
It was the cause of my problem. Thank a lot for you help.