Pregunta

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_()
¿Fue útil?

Solución

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:

msgBox = QMessageBox(self)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top