当前位置:网站首页>QT 一个控件的坐标怎么相对固定显示在另一个控件上(坐标系)
QT 一个控件的坐标怎么相对固定显示在另一个控件上(坐标系)
2022-06-28 21:08:00 【Licht小粉】
先给子控件设置它依赖于哪一个控件上显示
void setTableViewParent(QWidget *parent = 0);
void ComplexCombox::setTableViewParent(QWidget *parent)
{
m_tableView->setParent(parent);
m_tableView->setVisible(false);
}设置坐标的时候,就会相对那个控件的坐标显示
m_tableView->setGeometry(x,y,414,290);示例:
complexCombox->setTableViewParent(ui->groupBox_3);
complexCombox->setTableViewPos(ui->groupBox_3->pos().x()+15,ui->groupBox_3->pos().y()+150);
这样的话,不管怎么移动窗口,tableview显示的坐标都跟着groupBox的坐标而移动。
补充一下QT里坐标系的知识:
- 绝对位置:相对于桌面窗口原点(0,0)的位置
- 相对位置:相对于应用程序原点(0,0)的位置
与鼠标位置有关的3个方法
- QCursor::pos() 的结果是鼠标相对于桌面的绝对位置
- mousePressEvent的参数event的位置,event->pos() 是鼠标相对于应用程序的位置
- event->globalPos() 相对于桌面原点的位置,绝对位置
示例:
void Qt_Pos::MainWindow(QMouseEvent* event)
{
QPoint p1 = QCursor::pos();
QString str1 = QString::number(p1.x()) + " , " + QString::number(p1.y());
QPoint p2 = event->pos();
QString str2 = QString::number(p2.x()) + " , " + QString::number(p2.y());
QPoint p3 = event->globalPos(); //相对于桌面原点的位置
QString str3 = QString::number(p3.x()) + " , " + QString::number(p3.y());
}
Qt是如何获取控件的相对位置示例:
QPoint p4 = ui.pushButton->pos(); //按钮控件相对于窗口原点的位置
Qt是如何获取控件的绝对位置示例:
QPoint p5 = ui.pushButton->mapToGlobal(QPoint(0, 0)); //按钮相对于桌面原点的绝对位置
控件的大小:
QRect rect = ui.pushButton->rect();
QString str6 = QString::number(rect.width()) + " , " + QString::number(rect.height());
边栏推荐
- RT thread thread synchronization and thread communication
- Ref attribute, props configuration, mixin mixing, plug-in, scoped style
- 我也差点“跑路”
- Analysis of variance
- Leetcode daily question - 522 Longest special sequence II
- openGauss内核分析之查询重写
- 力扣树的进一步应用
- 开通挖财账号安全吗?是靠谱的吗?
- LeetCode226. Flip binary tree
- mysql-发生系统错误1067
猜你喜欢

Query rewriting for opengauss kernel analysis

如何使用 DataAnt 监控 Apache APISIX

RT thread thread synchronization and thread communication

学习太极创客 — MQTT 第二章(八)ESP8266 MQTT 用户密码认证

Ref attribute, props configuration, mixin mixing, plug-in, scoped style

Pyechart drawing multiple Y-axis line graphs

Leetcode 36. 有效的数独(可以,一次过)

The further application of Li Kou tree

ref属性,props配置,mixin混入,插件,scoped样式

Bitbucket 使用 SSH 拉取仓库失败的问题
随机推荐
rapid ssl通配符证书八百一年是正版吗
Data standardization processing
Interface test process
API gateway Apache APIs IX helps the evolution of snowball dual active architecture
Please allow the "imperfection" of the current domestic Tob
学习太极创客 — MQTT 第二章(七)ESP8266 MQTT 遗嘱应用
MongoDB——副本集与分片
精通数据分析能力,收入翻倍?什么才是最强竞争力
LeetCode188. The best time to buy and sell stocks IV
题解 The SetStack Computer(UVa12096)紫书P116STL的综合应用
Application of the purple book p113map of ananagrams (uva156)
How to recover after Oracle delete accidentally deletes table data
The comprehensive application of the setstack computer (uva12096) Purple Book p116stl
力扣树的进一步应用
Leetcode daily question - 522 Longest special sequence II
[learning notes] cluster analysis
题解 The Blocks Problem(UVa101)紫书P110vector的应用
[learning notes] factor analysis
接口测试流程
LeetCode每日一题——710. 黑名单中的随机数