问题
I am using python 2.7 and PyQt4 to make a gui; my experience is pretty limited. I wanted to use the QInputDialog and QMessageBox objects for some of the dialogs I need. I don't want to have the "?" in any dialogs I use. There is an answer posted on how to do this for a similar question How can I hide/delete the "?" help button on the "title bar" of a Qt Dialog?
That solution works for a standard QDialog. It amounts to:
message = QtGui.QDialog(self, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
This gets rid of the "?" and leaves the rest. I am not having the same results with the other classes. This is what I have tried for the QInput Dialog:
nameDialog = QtGui.QInputDialog(self, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
nameDialog = QtGui.QInputDialog(self, flags = QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
nameDialog = QtGui.QInputDialog(self, flags = QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint | ~QtCore.Qt.WindowContextHelpButtonHint)
nameDialog = QtGui.QInputDialog(self, flags = QtCore.Qt.WindowTitleHint | ~QtCore.Qt.WindowContextHelpButtonHint)
or
nameDialog = QtGui.QInputDialog(self)
nameDialog.setWindowFlags(QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
nameDialog.setWindowFlags(QtCore.Qt.WindowContextHelpButtonHint)
nameDialog.setWindowFlags(nameDialog.windowFlags() | ~QtCore.Qt.WindowContextHelpButtonHint)
newUser = nameDialog.getText(self, 'User change', 'Enter name:')
None of these produced any results. The same thing happened no matter which line I used: the dialog shows up with the "?" just like it does when no second argument is included.
The QMessageBox gave me other problems when I tried to remove the "?". This is what I tried:
mkDialog = QtGui.QMessageBox(self, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
and
mkDialog = QtGui.QMessageBox(self)
mkDialog.setWindowFlags(QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
The first method gives me an error "argument 1 has unexpected type MainWin" (MainWin is the parent class). The second method displays the dialog with no title bar at all.
This question was asked before, How to remove help button on QInputDialog, but it got marked as a duplicate of the first question I posted. The same solution does not work for QInputDialog or QMessageBox as QDialog so How can I hide/delete the "?" help button on the "title bar" of a Qt Dialog? is not any help.
Any new advice would be appreciated.
来源:https://stackoverflow.com/questions/38533775/pyqt4-qinputdialog-and-qmessagebox-window-flags