Currently, my dialog is something like this (see attached image) i..e no title bar. I want it to be a modal which blocks interaction with it's parent and at the same show title bar. Above solution doesn't works for mac. However below code works fine on ubuntu 22.04. I think this is platform specific issue.
class MyDialog(QtWidgets.QDialog):
def __init__(self, parent=None):
super().__init__(parent=parent)
self.setWindowTitle("My Dialog")
# Set modality to WindowModal
self.setWindowModality(Qt.WindowModal)
# Set appropriate window flags
# self.setWindowFlags(Qt.Dialog | Qt.Window)
# Set up the layout
layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(QtWidgets.QLabel("This is a dialog!"))
self.setLayout(layout)
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Main Window")
self.setGeometry(100, 100, 300, 200)
# Add a button to the main window
self.button = QtWidgets.QPushButton("Show Dialog", self)
self.button.setGeometry(100, 80, 100, 40)
self.button.clicked.connect(self.show_dialog)
def show_dialog(self):
dialog = MyDialog(self) # Create dialog with main window as parent
dialog.show() # Show the dialog (exec creates a modal dialog)
[image: 2b98569d-09be-42a2-8c14-987c693745f7.png]
This is how it looks on Ubuntu----
[image: c6c43930-8717-429d-af63-363e1ffd849c.png]