logo头像

技术引领生活!

windows平台Qt的setGeometry警告

经常出现setGeometry: Unable to set geometry

查看调用堆栈如下

图片
查看showEvent函数发现如果没有Qt::WA_Moved属性则会调用adjustPosition函数

1
2
3
4
5
6
7
8
9
10
void QDialog::showEvent(QShowEvent *event)
{
if (!event->spontaneous() && !testAttribute(Qt::WA_Moved)) {
Qt::WindowStates state = windowState();
adjustPosition(parentWidget());
setAttribute(Qt::WA_Moved, false); // not really an explicit position
if (state != windowState())
setWindowState(state);
}
}

解决方案

在调用show(); 以及相似函数前调用
设置Qt::WA_Moved刷卡

1
2
setAttribute(Qt::WA_Moved, true);
showMaximized();
支付宝打赏 微信打赏

您的支持是我前行的动力!