嵌入式Qt Qt 中的坐标系统

一.Qt中的坐标系统

实验1:窗口坐标大小

#include <QtGui/QApplication>
#include <QPushButton>
#include <QDebug>
#include "widget.h"
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    qDebug()<<"QWidget:";
    qDebug()<<w.x();
    qDebug()<<w.y();
    qDebug()<<w.width();
    qDebug()<<w.height();
    qDebug()<<"QWidget::geometry()";
    qDebug()<<w.geometry().x();
    qDebug()<<w.geometry().y();
    qDebug()<<w.geometry().width();
    qDebug()<<w.geometry().height();
    qDebug()<<"QWidget::frameGeometry()";
    qDebug()<<w.frameGeometry().x();
    qDebug()<<w.frameGeometry().y();
    qDebug()<<w.frameGeometry().width();
    qDebug()<<w.frameGeometry().height();
    return a.exec();
}

QWidget:
192
192
400
300
QWidget::geometry()
201
230
400
300
QWidget::frameGeometry()
192
192
418
347

实验2: 每个平台有自己的最小窗口设定,如果代码中设置的窗口大小 小于平台规定大小,那么会默认调整为平台规定的最小大小。

#include <QtGui/QApplication>
#include <QPushButton>
#include <QDebug>
#include "widget.h"
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.resize(100, 100);
    w.move(120, 120);
    w.show();
    qDebug()<<"QWidget:";
    qDebug()<<w.x();
    qDebug()<<w.y();
    qDebug()<<w.width();
    qDebug()<<w.height();
    qDebug()<<"QWidget::geometry()";
    qDebug()<<w.geometry().x();
    qDebug()<<w.geometry().y();
    qDebug()<<w.geometry().width();
    qDebug()<<w.geometry().height();
    qDebug()<<"QWidget::frameGeometry()";
    qDebug()<<w.frameGeometry().x();
    qDebug()<<w.frameGeometry().y();
    qDebug()<<w.frameGeometry().width();
    qDebug()<<w.frameGeometry().height();
    return a.exec();
}


QWidget:
120
120
152
100
QWidget::geometry()
129
158
152
100
QWidget::frameGeometry()
120
120
170
147

二.QPushButton 组件

实验3:QPushButton 使用

#include <QtGui/QApplication>
#include <QPushButton>
#include <QDebug>
#include "widget.h"
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    QPushButton b(&w);// 生成 QPushButton对象, 其父组件为 QWidget
    QPushButton b1(&w);
    b.setText("Button");// 设置显示的字符串
    b.move(10, 10);     // 移动到坐标 (10, 10)
    b.resize(100, 50);  // 设置大小 width = 100, height = 25

    b1.setText("Button"); // 设置显示的字符串
    b1.move(120, 10);      // 移动到坐标 (120, 10)
    b1.resize(100, 50);   // 设置大小 width = 100, height = 25

    w.resize(100, 100);
    w.move(120, 120);
    w.show();
    qDebug()<<"QWidget:";
    qDebug()<<w.x();
    qDebug()<<w.y();
    qDebug()<<w.width();
    qDebug()<<w.height();
    qDebug()<<"QWidget::geometry()";
    qDebug()<<w.geometry().x();
    qDebug()<<w.geometry().y();
    qDebug()<<w.geometry().width();
    qDebug()<<w.geometry().height();
    qDebug()<<"QWidget::frameGeometry()";
    qDebug()<<w.frameGeometry().x();
    qDebug()<<w.frameGeometry().y();
    qDebug()<<w.frameGeometry().width();
    qDebug()<<w.frameGeometry().height();
    return a.exec();
}

小结:

Qt中的几何坐标以左上角为原定。

  • 水平为X轴,从左向右为正向。

  • 垂直为Y轴,从上到下为正向。

Qt 中的GUI组件以左上角进行定位。

Qt 中的GUI组件可以在坐标系统中进行大小设置。

相关推荐
AI原吾2 小时前
掌握Python-uinput:打造你的输入设备控制大师
开发语言·python·apython-uinput
机器视觉知识推荐、就业指导2 小时前
Qt/C++事件过滤器与控件响应重写的使用、场景的不同
开发语言·数据库·c++·qt
毕设木哥2 小时前
25届计算机专业毕设选题推荐-基于python的二手电子设备交易平台【源码+文档+讲解】
开发语言·python·计算机·django·毕业设计·课程设计·毕设
珞瑜·2 小时前
Matlab R2024B软件安装教程
开发语言·matlab
weixin_455446172 小时前
Python学习的主要知识框架
开发语言·python·学习
孤寂大仙v2 小时前
【C++】STL----list常见用法
开发语言·c++·list
她似晚风般温柔7893 小时前
Uniapp + Vue3 + Vite +Uview + Pinia 分商家实现购物车功能(最新附源码保姆级)
开发语言·javascript·uni-app
咩咩大主教3 小时前
C++基于select和epoll的TCP服务器
linux·服务器·c语言·开发语言·c++·tcp/ip·io多路复用
FuLLovers4 小时前
2024-09-13 冯诺依曼体系结构 OS管理 进程
linux·开发语言
everyStudy4 小时前
JS中判断字符串中是否包含指定字符
开发语言·前端·javascript