![]() |
PyQt: Python and Qt GUI - customized Dialogs - close Event handling - connection
Hello,
I guess this is a totally noob question. But I stuck and don't know how to handle... I've had to reebot my N900 to often (made a not cancelable modal Dialog by accident) and hope now here for help for my initial problem. Here a example of my problem: I created a Main Window and a Menu to call a Test Dialog (want to place some widgets there) I know I have to close the Dialog after the accept or rejected event. But I don't know how. Dialog.close doesn't work. DialogTest.py: Code:
import sysUi_frmMain.py: Code:
# -*- coding: utf-8 -*-Ui_frmDialog.py: Code:
# -*- coding: utf-8 -*-Before I post here some examples of my stupid fault trys... Could someone please help me and post the solution? :) |
Re: PyQt: Python and Qt GUI - customized Dialogs - close Event handling - connection
Do something like this in your dialog
Code:
def on_backButton_clicked(self): |
Re: PyQt: Python and Qt GUI - customized Dialogs - close Event handling - connection
You might want to call QDialog.accept() after your print statement when overriding the accept method. Same for reject().
|
Re: PyQt: Python and Qt GUI - customized Dialogs - close Event handling - connection
Thanks for your fast answer. :-)
Quote:
The self.close() is the argument to close the Dialog, is that correct? But with this minimalistic code in DialogTest.py it doesn't work: Code:
class frmDialog(QtGui.QDialog): |
Re: PyQt: Python and Qt GUI - customized Dialogs - close Event handling - connection
You should not have to re-implement those events just for a close.
here some code that works, generated from qt designer. it opens a main window, with a big button that shows the dialog. dialog has two buttons that accept and reject then closes the dialog. main.py Code:
#!/usr/bin/env pythonCode:
# -*- coding: utf-8 -*-Code:
# -*- coding: utf-8 -*-Code:
# -*- coding: utf-8 -*- |
Re: PyQt: Python and Qt GUI - customized Dialogs - close Event handling - connection
Quote:
Your example worked just simple and easy. On my N900 and on my PC. I compared it with my code step by step and now I spent over 1 hour trying and fiddle out because of what part of the code my example and also my main project was not working. And now it was the LAST thing I had suspected. I used this in my Main program: Code:
def reject(self):Code:
QtCore.QObject.connect(self.cancelButton, QtCore.SIGNAL("clicked()"), Dialog.reject)But now using your function from your code and from your fist example it works perfect: Code:
def on_backButton_clicked(self):And I have to apologise myself... I'm not a big contributor at maemo talk. I'm a interested reader since November. But I hope while learning Python, Qt and how to deploy the one or other nice application to Maemo Extras I can help the comunity more than simply speculating about the next firmware relase. :) |
Re: PyQt: Python and Qt GUI - customized Dialogs - close Event handling - connection
Just connect the accepted() signal to a function in your class that does whatever work you need to do. It's pretty simple, as the dialog automatically closes. If you want to do some stuff in the event that the dialog is rejected, just connect the rejected() signal to a different function. Here's an example that subclasses the Qt Designer created classes:
Code:
class settingsDialog(QDialog, Ui_settingsDialog): |
Re: PyQt: Python and Qt GUI - customized Dialogs - close Event handling - connection
signals and slots is great, but Qtdesigner does much for you, as does IDE like eric. Try and stay with Designer as your interfaces get more complex, as it allows you to tweak layout much easier
anyway you get much pleasure for pyqt as you learn more.:D |
Re: PyQt: Python and Qt GUI - customized Dialogs - close Event handling - connection
Quote:
So to connect the accepted() signal to my function have also not worked. Simply renamed "accept" to "storesetting" and now it works. :mad: I guess I overrided with "reject" and "accept" other functions. Hmm... How can I see if I override a existing function? Quote:
I'm acctually trying with Eric and QtDesigner... but as a Windows .NET Framework developer I'm very cosseted. :( I miss the auto completion the most. I mean real auto completion, with the full knowledge of the full framework, all api's and the full namespace. Easy to search and click. Simple to know if you override a function, you want to see what events are provided or to find the exact name of a rarely used function. |
Re: PyQt: Python and Qt GUI - customized Dialogs - close Event handling - connection
In Eric click on generate dialog code, and it will show you all of the functions to connect to. Just click on the actions you want to react to and it will generate the stub code for you. You can then cut and paste it as you need.
|
| All times are GMT. The time now is 08:35. |
vBulletin® Version 3.8.8