查看完整版本: [-- 设置窗口居中显示 --]

QTCN开发网 -> Qt代码秀 -> 设置窗口居中显示 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

XChinux 2012-07-15 11:26

设置窗口居中显示


  1. void setWindowCenter(QWidget *window,
            double widthScale = 1, double heightScale = 1)
    {
        double ws = widthScale < 0.1 ? 0.1 : widthScale;
        double hs = heightScale < 0.1 ? 0.1 : heightScale;
        ws = ws > 1 ? 1 : ws;
        hs = hs > 1 ? 1 : hs;
        QRect rect = QApplication::desktop()->availableGeometry();
        int iTitleHeight = window->style()->pixelMetric(QStyle::PM_TitleBarHeight);
        window->setGeometry(rect.width() * (1 - ws) / 2,
                rect.height() * (1 - hs) / 2 + iTitleHeight,
                rect.width() * ws,
                rect.height() * hs - iTitleHeight);
    }


widthScale和heightScale为宽、高缩放系数

lyjbbq 2012-08-17 09:11
支持!!

zkzhou_10 2012-08-27 07:40
厉害!

gesturewei 2012-12-08 18:10
Mark,支持楼主~

sjpl00 2012-12-11 15:40
       支持,收藏

chuong 2012-12-13 17:28
似乎没考虑多显示器下的居中

XChinux 2012-12-14 08:43
引用第5楼chuong于2012-12-13 17:28发表的  :
似乎没考虑多显示器下的居中

没有,我这里也没有环境测试,有相关的模拟软件供测试吗?


查看完整版本: [-- 设置窗口居中显示 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled