gpt4 book ai didi

c++ - qt小部件位置

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:21:16 25 4
gpt4 key购买 nike

我有一个网格布局的主窗口,两行有 8 个按钮。

 ---------------------
| |
| 1 2 3 4 |
| |
| |
| 5 6 7 8 |
| |
---------------------

我试图在单击的按钮旁边显示一个弹出对话框。因此,我试图获取连接到 clicked() 信号的插槽中按钮的坐标。

我试过了

QPoint p = btn->pos();

QPoint p = btn->geometry().topLeft();

并且出于某种原因两者都是 (0, 0)。如何获取在该插槽中单击的按钮的位置?

谢谢

最佳答案

我认为您需要映射按钮相对于父窗口的位置。

QWidget::mapTo

Translates the widget coordinate pos to the coordinate system of parent. The parent must not be 0 and must be a parent of the calling widget.

关于c++ - qt小部件位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11594634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com