[英]QWidget and showing of QMessageBox
我有一個QWidget,它在show事件中顯示一個QMessageBox。 我已經覆蓋了QWidget的showEvent函數。 問題是,首先顯示消息框,稍后顯示小部件的其余部分。 我該如何解決這個問題?
void InstallScreen::showEvent( QShowEvent *s )
{
QMessageBox::about( m_main, "One Click Installer",
QString( "The following repositories will be added \n %1" ).arg( repoList ) );
QMessageBox::about( m_main, "One Click Installer",
QString( "The following packages will be installed \n %1" ).arg( packList ) );
}
使用延遲調用來顯示窗口小部件,例如將窗口小部件顯示代碼放在插槽中並使用QTimer :: singleShot調用它,延遲為0秒。
這將允許showEvent 在顯示窗口小部件之前完全處理並在mainloop上安排任何重繪事件。 這將使小部件和消息框彼此獨立地顯示/繪制/重新繪制。
protected:
void MyWidget::showEvent(...) {
...
QTimer::singleShot(0, this, SLOT(showMessageBox());
}
private slots:
void MyWidget::showMessageBox() {
QMessageBox::information(...); // or whatever
}
如果您需要一些額外的余量(無論出於何種原因),請將定時器延遲設置為50或100 ms。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.