I would like to show a frameless modal dialog that does not provide any interaction, not even the ability to close the dialog. The idea is to open the dialog to display a message warning of a long operation going on, run that operation, than close the dialog.
The qt doc seems to indicate that it is possible to show a modal dialog without executing its event loop: https://doc.qt.io/qt-5/qdialog.html#modal-dialogs
But when I do it, the dialog never properly renders on screen. I get a black widget, and its labels remain invisible.
This is my attempt:
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class ModalInfoDialog(QDialog):
"""
Frameless modal dialog with no interaction
"""
def __init__(self, text1="Loading project",
text2="", parent=None):
super().__init__(parent)
self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint)
self.setModal(True)
self.setStyleSheet(
"""
QDialog {
background-color: white;
border: none;
}
""")
layout = QVBoxLayout(self)
self.setLayout(layout)
firstLine = QLabel(text1)
secondLine = QLabel(text2)
layout.addWidget(firstLine)
layout.addWidget(secondLine)
import time
app = QApplication([])
d = ModalInfoDialog("haha!", "huh?")
d.show()
QApplication.processEvents() # does not help
time.sleep(3)
d.close()