自定义 QDialog 窃取全屏应用程序焦点并显示任务栏
我想知道如何使用自己的按钮制作自定义 QDialog 消息框,类似于下面的代码。
到目前为止,我已经有了这段代码,它运行得很好。这段代码的问题在于它是从全屏应用程序启动的,并且它窃取了它的焦点(顶部的主任务栏与 QDialog 对象一起出现)。我希望它能够与后台的全屏应用程序无缝协作,这意味着当我单击按钮显示此消息框时,顶部不应出现任务栏。我正在使用 PyQt4 和 Python 2.7.2 在 Ubuntu 11.10 中工作。
btnOne = QPushButton("One", self)
btnTwo = QPushButton("Two", self)
btnOne.clicked.connect(self.workForOne)
btnTwo.clicked.connect(self.workForTwo)
msgBox = QMessageBox()
msgBox.setText("<center>This is a custom question!</center>")
msgBox.setWindowTitle("Question")
msgBox.setWindowModality(Qt.ApplicationModal)
msgBox.addButton(btnOne, QMessageBox.ActionRole)
msgBox.addButton(btnTwo, QMessageBox.ActionRole)
msgBox.addButton(QMessageBox.Cancel)
msgBox.exec_()
I was wondering how I can make a custom QDialog message box with my own buttons, similar to the code below.
So far I have this code, which works pretty well. The problem with this code is that it launches from a full screen application, and it steals the focus of it (the main taskbar on the top appears along with the QDialog object). I want this to work seamlessly with my fullscreen application in the background, meaning no taskbar at the top should appear when I click on a button to show this message box. I'm working in Ubuntu 11.10 with PyQt4 and Python 2.7.2.
btnOne = QPushButton("One", self)
btnTwo = QPushButton("Two", self)
btnOne.clicked.connect(self.workForOne)
btnTwo.clicked.connect(self.workForTwo)
msgBox = QMessageBox()
msgBox.setText("<center>This is a custom question!</center>")
msgBox.setWindowTitle("Question")
msgBox.setWindowModality(Qt.ApplicationModal)
msgBox.addButton(btnOne, QMessageBox.ActionRole)
msgBox.addButton(btnTwo, QMessageBox.ActionRole)
msgBox.addButton(QMessageBox.Cancel)
msgBox.exec_()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您遇到的问题是您没有为您的
msgBox
提供父级。这使得 Qt 将其视为顶级窗口。尝试将消息框的实例化更改为如下所示:I think the issue you're having is that you aren't giving your
msgBox
a parent. This makes Qt treat it as a top-level window. Try changing your instantiation of your message box to look like this: