代码如下:
- XXX::XXX(QWidget *parent
- {
- ..................
-
- resize(300, 300);
- int cx, cy;
-
- if( NULL == parent )
- {
- cx = (QApplication::desktop()->width() - width()) / 2;
- cy = (QApplication::desktop()->height() - height()) / 2;
- }
-
- else
- {
- cx = ( parent->width() - width() ) / 2;
- cy = ( parent->height() - height() ) / 2;
- }
- move(cx, cy);
- ....................
- }
这段代码太常用了,就发上来和大家共享一下吧,呵呵。
http://blog.csdn.net/small_qch/article/details/6973956
QT 让窗口(或控件)居中
原文:http://www.cnblogs.com/findumars/p/4851301.html