I want to print the value when changing the value of the dialog called by the getInt
method of QInputDialog
.
I run the below code, but it is not working:
import sys
from PyQt5.QtCore import Slot
from PyQt5.QtWidgets import QApplication, QInputDialog
@Slot(int)
def int_value_changed(val):
print(val)
if 'qapp' not in globals():
qapp = QApplication(sys.argv)
dlg = QInputDialog(None)
dlg.intValueChanged.connect(int_value_changed)
dlg.getInt(None, 'title', 'Type Value', 0)
Functions like
getInt
are static, which means they create an internal instance ofQInputDialog
which is not directly accessible from code. If you create your own instance ofQInputDialog
, you must do all the initialisation yourself and then callexec()
(just like an ordinary dialog). As the documentation for QInputDialog shows, this approach is more flexible than using the static functions, since it provides much more scope for customisation.A roughly equivalent implementation of
getInt
would be: