2012-03-25 3 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));