framelesshelper
framelesshelper copied to clipboard
Utilities::mapOriginPointToWindow is wrong in some cases
// utilities.cpp
QPointF Utilities::mapOriginPointToWindow(const QObject *object) {
Q_ASSERT(object);
if (!object) {
return {};
}
if (!object->isWidgetType() && !object->inherits("QQuickItem")) {
qWarning() << object << "is not a QWidget or a QQuickItem.";
return {};
}
QPointF point = {object->property("x").toReal(), object->property("y").toReal()};
for (QObject *parent = object->parent(); parent; parent = parent->parent()) {
point += {parent->property("x").toReal(), parent->property("y").toReal()};
if (parent->isWindowType()) { // If obj is a dialog which has a parent window, then the last addition is redundant
break;
}
}
return point;
}
This function does not apply to dialogs. When a frameless window's WindowFlags contains Qt::Dialog and it has parent widget, it's QWidget::isWindowType returns false but looks like a window however. What's really strange is that it's QWidget::pos() returns its absolute coordinates in the screen instead of coordinates relative to the parent widget, in this case, this function obviously adds the coordinates of its parent widget unnecessarily. So why not directly call QWidget::mapToGlobal? I'm using Qt 5.15.2.
好的,我研究下。
你那边必须要使用Qt::Dialog
吗,能不能用普通的widget代替?
有时候需要一个嵌入的Dialog,虽然也能实现阻塞,但这样就有两个窗口,有些情况下就显得麻烦。反正我也不用quick,暂时用QWidget::mapToGlobal解决了。
代码里没有直接使用QWidget::mapToGlobal
是因为想避免直接依赖QWidget模块,不过你这样改也可以,从原理上来讲是没错的。你自己用的话就那么改吧,不会导致什么问题
可以,但是这个问题可以注意一下。
Duplicates #83