PyQt signals/slots dialogs question

I'm just starting to get to grips with PyQt, and I'm having a bit of
trouble connecting slots / signals, or understanding how I should do
so to achieve what I am after.

I am trying to write an application that will display a sequence of
dialogs, with back / next / cancel buttons to step through the
dialogs. Each dialog will capture user input, ask the user to browse
for a file, present some radio-buttons for a selection etc..

I've put the dialogs together in Designer, and I come to startup the
app with a small piece of python code, create an instance of each
dialog, and then connect up the buttons to any methods needed to
control the movement through the dialogs etc.

I'm having a brain-freeze though, and just can't figure out what I
should be doing next, or the best approach to take.

for example, Currently I am thinking I would need to connect the
clicked() signal of the Next button on dialog 1 to a method say,
'dialog1Next' that would then hide dialog1 and show dialog2. I would
then need to connect Dialog 2's clicked() signal of its next button to
a method called 'dialog2Next' that hides dialog2 and shows dialog3
etc...

I would also, for example, need methods for dialog2Back,
dialog2cancel, dialog1cancel etc..

I'm having trouble figuring out how to setup the connections, and
where the slot-methods should live..

I have this so far;

from PyQt4 import QtCore, QtGui
from WELCOME import Ui_Dialog as welcomeDialog
from SOURCE_TYPE_SELECT import Ui_Dialog as sourceTypeSelectDialog
from SOURCE_TYPE_CONFIRMATION import Ui_Dialog as
sourceTypeConfirmationDialog
from ACCEPT_EULA import Ui_Dialog as acceptEulaDialog
from CONFIRM_REQUIREMENTS import Ui_Dialog as
confirmRequirementsDialog
from SOURCE_BINARY_LOCATE import Ui_Dialog as sourceBinaryLocateDialog
from SOURCE_BINARY_PROBLEMS import Ui_Dialog as
sourceBinaryProblemsDialog
from OUTFILE_LOCATE import Ui_Dialog as outfileLocateDialog
from OUTFILE_PROBLEMS import Ui_Dialog as outfileProblemsDialog
from COLLECTION_PROGRESS import Ui_Dialog as collectionProgressDialog
from OUTFILE_LOCATION import Ui_Dialog as outfileLocationDialog

My questions are, am I approaching this the right way, with a method
per action per dialog to move through the dialogs, and just how do I
setup the connections I need. I'm getting confused with scope etc. IE:
if the connect is right, and WelcomeNext fires, how can it refer to
myapp.SourceTypeSelect.show() or myapp.Welcome.hide()

Advertisements

On Mon, 7 Jun 2010 08:22:07 -0700 (PDT), AlienBaby
<>
wrote:
> Hi,
>
> I'm just starting to get to grips with PyQt, and I'm having a bit of
> trouble connecting slots / signals, or understanding how I should do
> so to achieve what I am after.
>
> I am trying to write an application that will display a sequence of
> dialogs, with back / next / cancel buttons to step through the
> dialogs. Each dialog will capture user input, ask the user to browse
> for a file, present some radio-buttons for a selection etc..
>
> I've put the dialogs together in Designer, and I come to startup the
> app with a small piece of python code, create an instance of each
> dialog, and then connect up the buttons to any methods needed to
> control the movement through the dialogs etc.
>
> I'm having a brain-freeze though, and just can't figure out what I
> should be doing next, or the best approach to take.
>
> for example, Currently I am thinking I would need to connect the
> clicked() signal of the Next button on dialog 1 to a method say,
> 'dialog1Next' that would then hide dialog1 and show dialog2. I would
> then need to connect Dialog 2's clicked() signal of its next button to
> a method called 'dialog2Next' that hides dialog2 and shows dialog3
> etc...
>
> I would also, for example, need methods for dialog2Back,
> dialog2cancel, dialog1cancel etc..
>
> I'm having trouble figuring out how to setup the connections, and
> where the slot-methods should live..
>
> I have this so far;
>
> from PyQt4 import QtCore, QtGui
> from WELCOME import Ui_Dialog as welcomeDialog
> from SOURCE_TYPE_SELECT import Ui_Dialog as sourceTypeSelectDialog
> from SOURCE_TYPE_CONFIRMATION import Ui_Dialog as
> sourceTypeConfirmationDialog
> from ACCEPT_EULA import Ui_Dialog as acceptEulaDialog
> from CONFIRM_REQUIREMENTS import Ui_Dialog as
> confirmRequirementsDialog
> from SOURCE_BINARY_LOCATE import Ui_Dialog as sourceBinaryLocateDialog
> from SOURCE_BINARY_PROBLEMS import Ui_Dialog as
> sourceBinaryProblemsDialog
> from OUTFILE_LOCATE import Ui_Dialog as outfileLocateDialog
> from OUTFILE_PROBLEMS import Ui_Dialog as outfileProblemsDialog
> from COLLECTION_PROGRESS import Ui_Dialog as collectionProgressDialog
> from OUTFILE_LOCATION import Ui_Dialog as outfileLocationDialog
>
>
>
> class StartQT4(QtGui.QDialog):
> def __init__(self, parent=None):
> QtGui.QWidget.__init__(self, parent)
> self.Welcome = welcomeDialog()
> self.Welcome.setupUi(self)
> self.SourceTypeSelect = sourceTypeSelectDialog()
> self.SourceTypeConfirmation = sourceTypeConfirmationDialog()
> self.AcceptEula = acceptEulaDialog()
> self.ConfirmRequirements=confirmRequirementsDialog()
> self.SourceBinaryLocate=sourceBinaryLocateDialog()
> self.SourceBinaryProblems=sourceBinaryProblemsDialog()
> self.OutfileLocate=outfileLocateDialog()
> self.OutfileProbelms=outfileProblemsDialog()
> self.CollectionProgress=collectionProgressDialog()
> self.OutfileLocation=outfileLocationDialog
>
> #Connect up next/back/cancel etc.. buttons
>
> ??? self.Welcome.connect(self.Welcome.welcomeNext,
> QtCore.SIGNAL("clicked()"),WelcomeNext)
>
>
>
> def WelcomeNext():
> #Code here to hide Welcome dialog and show SourceTypeSelect
> dialog
>
>
>
> if __name__ == "__main__":
> app = QtGui.QApplication(sys.argv)
> myapp = StartQT4()
> myapp.show()
> sys.exit(app.exec_())
>
>
>
>
>
> My questions are, am I approaching this the right way, with a method
> per action per dialog to move through the dialogs, and just how do I
> setup the connections I need. I'm getting confused with scope etc. IE:
> if the connect is right, and WelcomeNext fires, how can it refer to
> myapp.SourceTypeSelect.show() or myapp.Welcome.hide()
>
>
> Any help much appreciated.

Sounds like you are trying to build a wizard the hard way.

Use Designer to create a QWizard with the contents of each of your dialogs
as a QWizardPage.

Instead of using a 'WelcomeNext' method as the slot, should I just
connect the clicked() signal to both the hide slot of the welcome
dialog and the show slot of the SourceTypeSelect dialog? .. though
then where would any code I wanted to run say, (for the sake of
argument) between the hiding of one dialog and the showing of the
next?

On Jun 7, 5:21 pm, AlienBaby <> wrote:
> My real aim here is to learn pyqt, so I would rather not the the
> QWizard process until I understand myself whats going on behind the
> scenes.

Perhaps I posted to early, but a little more perserverance and I have
managed to unthaw the brain and move forward. I've ended up with the
following. It does what I need, and now it's working I can think
around how to implement with a better approach;

from PyQt4 import QtCore, QtGui
from WELCOME import Ui_Dialog as welcomeDialog
from SOURCE_TYPE_SELECT import Ui_Dialog as sourceTypeSelectDialog
from SOURCE_TYPE_CONFIRMATION import Ui_Dialog as
sourceTypeConfirmationDialog

On 06/07/2010 08:21 PM, AlienBaby wrote:
> On Jun 7, 5:21 pm, AlienBaby <> wrote:
>
>> My real aim here is to learn pyqt, so I would rather not the the
>> QWizard process until I understand myself whats going on behind the
>> scenes.
>>
> Perhaps I posted to early, but a little more perserverance and I have
> managed to unthaw the brain and move forward. I've ended up with the
> following. It does what I need, and now it's working I can think
> around how to implement with a better approach;
>
I haven't done much Qt programming, and all of it in C++, but anyway:

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!