'how to ignore input to dialog based application while QProcess is running
I created a basic "Dialog without buttons" application using Qt5 Designer. I have a context menu that starts a QProcess that allows the user to view/edit a file. The main dialog seems disabled while the QProcess is running, but it is still processing input and when the user closes the editor, the main dialog processes all of its queued up input events. I would like the dialog to ignore all input while the QProcess is running. I would like the main dialog to be modal, but I can't seem to make it modal. How can I ignore all input to the main dialog while the QProcess is running?
class Ui_GitStatusDialog(QDialog):
# member variables
startDirs = []
exceptDirs = []
isVerbose = False
terminal = ''
standardView = ''
imageView = ''
def __init__(self):
super().__init__()
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.setWindowModality(QtCore.Qt.ApplicationModal)
Dialog.resize(724, 612)
...
def eventFilter(self, source, event):
if event.type() == QEvent.ContextMenu and source is self.fileList:
path = self.repositoryList.currentItem().text()
file = source.currentItem().text()
ext = file[1 + file.find('.'):]
endOfFile = 2 + file.find(':')
contextMenu = QMenu()
normAct = None
diffAct = None
imageAct = None
bDisplayMenu = False
action = None
if ext == 'png' or ext == 'jpg' or ext == 'bmp':
imageAct = contextMenu.addAction('image view')
bDisplayMenu = True
elif file.startswith('modified: '):
diffAct = contextMenu.addAction('difference view')
normAct = contextMenu.addAction('normal view')
endOfFile += 1
bDisplayMenu = True
elif file.startswith('untracked: ') or \
file.startswith('added: ') or \
file.startswith('copied: ') or \
file.startswith('renamed: '):
normAct = contextMenu.addAction('normal view')
endOfFile += 1
bDisplayMenu = True
elif endOfFile == 1:
normAct = contextMenu.addAction('normal view')
bDisplayMenu = True
if bDisplayMenu:
action = contextMenu.exec_(event.globalPos())
if action != None:
if action == imageAct:
command = self.imageView + ' ' + path + file[endOfFile:]
process = QProcess(self)
# self.btnClose.setEnabled(False) - this doesn't work
# self.btnRefresh.setEnabled(False) - this doesn't work
# self.hide() - this doesn't work
self.setModal(True) - this doesn't work
process.start(command)
process.waitForFinished()
# self.btnClose.setEnabled(True)
# self.btnRefresh.setEnabled(True)
return True
elif action == normAct:
...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
