2012-03-25 71 views

回答

1

使用QDesktopWidget獲得屏幕幾何圖形(不要被其名稱^^嚇倒)。

//Sample code 
QRect screen = qApp->desktop()->screenGeometry(); 
int iconSize = 64; 
p3->setGeometry(QRectF(screen.width()/2 - iconSize/2, screen.height()/2 - iconSize/2, iconSize, iconSize)); 
1

最好的辦法是使用佈局而不是硬編碼位置。使用佈局允許您使用Qt.Align來居中QWidgets。

如果你不想使用佈局。你可以做類似於

int xpos = parent->width()/2 - p3->width()/2 
int ypos = parent->height()/2 - p3->height()/2 
p3->setGeometry(QRectF(xpos,ypos, 64.0, 64.0)); 
相關問題