可以 QWidget::mapToGlobal
当小部件不可见时工作?我在手册上找不到任何内容。如果不能 为什么?
最佳答案
我刚刚写了一个小程序,调用 QWidget::mapToGlobal( QPoint( 0,0 ) )
在隐藏的小部件上。我发现我得到的位置是变化的,这取决于在我查询它的位置之前小部件是否已经显示在屏幕上。
QWidget::mapToGlobal()文档说:
Translates the widget coordinate pos to global screen coordinates. For example, mapToGlobal(QPoint(0,0)) would give the global coordinates of the top-left pixel of the widget.
读到这里,如果小部件不可见,它就不可能在屏幕上有保证的全局位置,这似乎是合乎逻辑的。
通过调用该方法获得的实际结果似乎取决于小部件上次显示的位置(如果有)。因此,依赖这种行为在当前或 future 版本的 Qt 中保持稳定似乎是不明智的。
关于qt - QWidget::mapToGlobal() 当小部件不可见时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7407540/