嵌入式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组件可以在坐标系统中进行大小设置。

相关推荐
还债大湿兄40 分钟前
《C++内存泄漏8大战场:Qt/MFC实战详解 + 面试高频陷阱破解》
c++·qt·mfc
倔强青铜33 小时前
苦练Python第18天:Python异常处理锦囊
开发语言·python
u_topian3 小时前
【个人笔记】Qt使用的一些易错问题
开发语言·笔记·qt
珊瑚里的鱼4 小时前
LeetCode 692题解 | 前K个高频单词
开发语言·c++·算法·leetcode·职场和发展·学习方法
AI+程序员在路上4 小时前
QTextCodec的功能及其在Qt5及Qt6中的演变
开发语言·c++·qt
xingshanchang4 小时前
Matlab的命令行窗口内容的记录-利用diary记录日志/保存命令窗口输出
开发语言·matlab
Risehuxyc4 小时前
C++卸载了会影响电脑正常使用吗?解析C++运行库的作用与卸载后果
开发语言·c++
AI视觉网奇4 小时前
git 访问 github
运维·开发语言·docker
不知道叫什么呀4 小时前
【C】vector和array的区别
java·c语言·开发语言·aigc
liulilittle5 小时前
.NET ExpandoObject 技术原理解析
开发语言·网络·windows·c#·.net·net·动态编程