Qt Jambi中获取屏幕尺寸、设置QWidget的坐标
需求:
在Qt Jambi中,我想获取当前屏幕的size以及Window或Widget的size,然后自由设置Window或Widget启动时在屏幕中的位置
解决方案:
?
package org.syxc.test;import com.trolltech.qt.core.QSize;import com.trolltech.qt.gui.*;public class LogonWindow extends QWidget {Ui_LogonWindow ui = new Ui_LogonWindow();private void initHandler() {QDesktopWidget desktop = QApplication.desktop();QSize windowSize;int screenWidth, width;int screenHeight, height;int x, y;setWindowTitle("登录");setWindowIcon(new QIcon("classpath:assets/icons/AIRApp_16.png"));resize(250, 500);// get screen sizescreenWidth = desktop.width();screenHeight = desktop.height();// get LogonWindow sizewindowSize = size();width = windowSize.width();height = windowSize.height();x = (screenWidth - width) / 2;y = (screenHeight - height) / 2;// set LogonWindow positionmove(x, y);}public LogonWindow() {ui.setupUi(this);this.initHandler();}public LogonWindow(QWidget parent) {super(parent);ui.setupUi(this);}}
?Qt Jambi中如此,Qt中的思路应该也差不多,有兴趣可以试试!
?