Sorry, that is not a valid solution. That makes the dialog box modeless;
it's the same as doing `self.d.setWindowModality(Qt.NonModal)`. The user
can then access the MainWindow dialog, which I don't want.
Any suggestions?
On Tuesday, February 9, 2021 at 12:14:32 PM UTC-5 Efrem Braun wrote:
> Solution:
>
> Replace:
> `self.d = CustomDialog(self)`
> with:
> `self.d = CustomDialog()`
>
> Then, using Qt.WindowModal won't anchor the dialog to its parent window,
> since it doesn't have a parent window.
>
> Efrem Braun
>
> On Tuesday, February 9, 2021 at 11:09:28 AM UTC-5 Efrem Braun wrote:
>
>> Update:
>>
>> Apparently the pyqtgraph context menu only gets blocked on a Mac. When I
>> run the working example using `Qt.ApplicationModal` on my Ubuntu OS, I can
>> access the context menu. Still trying to figure out how to fix this issue
>> on a Mac...
>>
>> Efrem Braun
>>
>> On Monday, February 8, 2021 at 11:56:14 PM UTC-5 Efrem Braun wrote:
>>
>>> 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/d0ce790d-c339-4c80-971d-1549cc313c81n%40googlegroups.com.