編輯看起來更科學:我已經改變通話的任意數量 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