gpt4 book ai didi

c++ - 在 MousePressEvent 中使用 QDialog

转载 作者:行者123 更新时间:2023-11-28 02:28:15 26 4
gpt4 key购买 nike

我有一个类,它是 QDialog 的子类,没有覆盖 exec()accept()reject() 和另一个调用 mousePaintEvent 中的 Dialog 类:

void Canvas::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton){
if (dialog->isVisible()){
dialog->setModal(true);
dialog->move(QWidget::mapToGlobal(event->pos()));
//I connect the dialog's accepted signal to the CallingClass's slot, that uses the information taken from the dialog
connect(dialog, &Dialog::accepted, this, &CallingClass::slot);
dialog->exec();
}
}
if (dialog->isVisible()){
if (dialog->rect().contains(event->pos())){
dialog->reject();
}
}
}

我试过使用对话框的存在性来检查,但是 delete 并没有真正起作用(我把它放在 dialog.reject() 之后),我什至尝试使用 bool,我,再次,在最后一个 if 中的 dialog.reject() 之后设置为 false,但我开始认为,在 .reject() 之后没有任何效果。我该如何继续?

最佳答案

我的理解是 dialog->rect() 不会给你你想要的东西(见 this )。不幸的是我现在无法测试它,但我认为你应该尝试将它与 pos 结合使用或直接尝试使用 frameGeometry .有了这个,您将拥有窗口相对于其父窗口的真实位置和大小。尝试查看您从点击事件获得的坐标值和这些方法的值,以便弄清楚如何使用它们......基本上您需要决定是否使用相对于您的桌面的全局坐标父窗口。

关于c++ - 在 MousePressEvent 中使用 QDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29798809/

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