简体   繁体   English

自定义QDialog窃取全屏应用程序焦点并显示任务栏

[英]Custom QDialog stealing fullscreen application focus and showing the taskbar

I was wondering how I can make a custom QDialog message box with my own buttons, similar to the code below. 我想知道如何用自己的按钮制作自定义QDialog消息框,类似于下面的代码。

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). 这段代码的问题在于它是从全屏应用程序启动的,并且占据了它的焦点(顶部的主任务栏与QDialog对象一起出现)。 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. 我正在使用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 think the issue you're having is that you aren't giving your msgBox a parent. 我认为您遇到的问题是您没有为msgBox设置父项。 This makes Qt treat it as a top-level window. 这使得Qt将其视为顶级窗口。 Try changing your instantiation of your message box to look like this: 尝试将您的消息框实例化为如下所示:

msgBox = QMessageBox(self)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM