zoukankan      html  css  js  c++  java
  • QT 让窗口(或控件)居中

    代码如下:

    1. XXX::XXX(QWidget *parent /* = 0 */)  
    2. {  
    3.     ..................  
    4.     //注意,resize一定要放在这段代码的前面  
    5.     resize(300, 300);  
    6.     int cx, cy;  
    7.     //当parent为空时,窗口就显示在桌面中央  
    8.     if( NULL == parent )  
    9.     {  
    10.         cx = (QApplication::desktop()->width() - width()) / 2;  
    11.         cy = (QApplication::desktop()->height() - height()) / 2;  
    12.     }  
    13.     //否则,控件就显示在父部件中央  
    14.     else  
    15.     {  
    16.         cx = ( parent->width() - width() ) / 2;  
    17.         cy = ( parent->height() - height() ) / 2;  
    18.     }  
    19.     move(cx, cy);  
    20.     ....................  
    21. }  


    这段代码太常用了,就发上来和大家共享一下吧,呵呵。

    http://blog.csdn.net/small_qch/article/details/6973956

  • 相关阅读:
    常见设备标记长度查询
    word怎么在方框中打对号
    shell dict 操作
    词表数据转换
    GoLand tool tips
    mac使用技巧
    人生三大陷阱
    【js重学系列】执行上下文
    uniapp-ui库
    【js重学系列】instanceof
  • 原文地址:https://www.cnblogs.com/findumars/p/4851301.html
Copyright © 2011-2022 走看看