Not sure if this has a straightforward solution, but I want to write a function that shows a dialog (defined elsewhere in a class that inherits QDialog
) and returns the user input when the user has finished interacting with the dialog. In other words, something similar to the QFileDialog::getOpenFileName
static method, where a single line can open the dialog and return the user's input, instead of employing the cumbersome (in this case) signal/slot mechanism.
Intended use:
/* Shows the dialog, waits until user presses OK or Cancel,
then returns the user's choice.
*/
result = createDialogAndReturnUserChoice()
I am currently working in PyQt but I'm fine with answers in the traditional Qt4 C++ framework.
EDIT//
Here's how to do it:
dialog = CustomDialog() # creates the custom开发者_高级运维 dialog we have defined in a class inheriting QDialog
if dialog.exec_(): # on exec_(), the whole program freezes until the user is done with the dialog; it returns the response of the user
# success
else:
# failure
It sounds like you have everything in place that you need. You can make a static function in your QDialog
derived class that does what you want. You can create a struct or class that encapsulates the data the user will generate and return it from your static function. Qt includes all the source code so you can look at QFileDialog::getOpenFileName()
in qfiledialog.cpp
and see what they do.
Edit: Sorry, I missed that you are working in Python. I don't know what facilities the language has for extending a C++ class and static methods.
精彩评论