I have an application which has a pyqtgraph instance in a dialog box. I 
want this dialog box to be modal (I don't want the user to be able to 
interact with the main window while the dialog box is open), so normally I 
would set `setWindowModality()` to `Qt.ApplicationModal`. However, this 
blocks the pyqtgraph's context menu from being accessible (I can right 
click on the pyqtgraph instance, and it shows me the context menu, but I'm 
not allowed to click on it).

I tried instead to set `setWindowModality()` to `Qt.WindowModal`. However, 
this locks the dialog box to the main window, which I don't like (I want 
the user to be able to see the main window while interacting with the 
dialog box).

Is there anyway to either:
1. Use  `setWindowModality(Qt.ApplicationModal)` but not block the 
pyqtgraph context menu?
or
2. Use  `setWindowModality(Qt.WindowModal)` but be able to undock the 
dialog box?

A minimal working example showing the behavior is below. You can see the 3 
behaviors that result when setting the window modality to 
Qt.ApplicationModal, Qt.WindowModal, and Qt.NonModal.

```
from PySide2.QtWidgets import *
from PySide2.QtGui import *
from PySide2.QtCore import *

import pyqtgraph as pg

class MainWindow(QMainWindow):
    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)
        b = QPushButton()
        b.setText("Open dialog")
        self.setCentralWidget(b)
        b.clicked.connect(self.showdialog)

    def showdialog(self):
        self.d = CustomDialog(self)

#        # not modal
#        self.d.setWindowModality(Qt.NonModal)
#        self.d.show()

        # location can't be moved
        self.d.setWindowModality(Qt.WindowModal)
        self.d.exec_()

#        # blocks context menu
#        self.d.setWindowModality(Qt.ApplicationModal)
#        self.d.exec_()


class CustomDialog(QDialog):
    def __init__(self, *args, **kwargs):
        super(CustomDialog, self).__init__(*args, **kwargs)

        buttons = QDialogButtonBox.Cancel
        self.buttonBox = QDialogButtonBox(buttons)
        self.buttonBox.rejected.connect(self.reject)
        self.layout = QVBoxLayout()
        self.layout.addWidget(pg.PlotWidget(self))
        self.layout.addWidget(self.buttonBox)
        self.setLayout(self.layout)


if __name__ == '__main__':
   app = QApplication(sys.argv)
   window = MainWindow()
   window.show()
   sys.exit(app.exec_())
```

Thank you.

Efrem Braun

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/61551f5b-7d00-44ea-94af-53fa2e648a8en%40googlegroups.com.

Reply via email to