编辑看起来更科学:我已经改变通话的任意数量 processEvents
一个循环,检查返回值。
再次编辑:看来新版本并不安全:它可能卡在循环中。所以我已经在迭代次数上设置了限制。
原创:
请告诉我这件事。如果我可以被允许从我自己的代码来引用:
// BIG PAIN: We want to get the dialog box to caluclate its own size. But there is
// no simple way to do this. The following seems to work, but only if processEvents
// is called at least twice. God knows why:
setAttribute (Qt::WA_DontShowOnScreen, true) ; // Prevent screen flicker
show() ;
QEventLoop EventLoop (this) ;
for (int i = 0 ; i < 10 ; i++)
if (!EventLoop.processEvents()) break ;
hide() ;
setAttribute (Qt::WA_DontShowOnScreen, false) ;
int x = 99 ; // whatever
int y = 99 ; // whatever
// Make sure it fits on the screen
QRect ScreenRect = qApp -> desktop() -> availableGeometry (ApplicationData -> mainWindow) ;
if (x + frameGeometry().width() > ScreenRect.right())
x = ScreenRect.right() - frameGeometry().width() ;
if (x < ScreenRect.x()) x = ScreenRect.x() ;
if (y + frameGeometry().height() > ScreenRect.bottom())
y = ScreenRect.bottom() - frameGeometry().height() ;
if (y < ScreenRect.y()) y = ScreenRect.y() ;
move (x, y) ;
试试这个,有不同的呼叫号码processEvents
。 (在这些调用中,各种子小部件和子子小部件本身递归地大小。)
看到我最新的编辑。第一次编辑是不安全的。 – TonyK 2011-03-25 07:35:43