QT软件开发: 窗口打开固定在屏幕中间或者右下角

2022-01-12 10:32:39 浏览数 (1)

窗口打开默认在屏幕中间显示:

代码语言:javascript复制
CameraWidget::CameraWidget(QWidget *parent, int index) :
    QWidget(parent),
    ui(new Ui::CameraWidget)
{
    ui->setupUi(this);
 
    //隐藏标题栏
    setWindowFlags(Qt::FramelessWindowHint);//无边框 
 
    //窗口显示在屏幕正中间
    QDesktopWidget *desktop = QApplication::desktop();
    move((desktop->width()-this->width())/2,(desktop->height()-this->height())/2);
}

窗口打开默认在屏幕右下角显示:

代码语言:javascript复制
CameraWidget::CameraWidget(QWidget *parent, int index) :
    QWidget(parent),
    ui(new Ui::CameraWidget)
{
    ui->setupUi(this);
 
    //隐藏标题栏
    setWindowFlags(Qt::FramelessWindowHint);//无边框 
 
    //打开的窗口在屏幕右下角
    QDesktopWidget *widget= QApplication::desktop();
    move(widget->width()-this->width(),widget->height()-this->height());
}

0 人点赞