Absolute Beginner



  • I have tried out a few GUI Designers and am most impressed with Qt, so I am using it to create a very simple GUI, linking the .ui form into the Python program.
    I have succeeded in making buttons and radiobuttons work*, but can't work out how to write the actions for the rest of my GUI - a scrollbox and the menubar File/Open,Quit and Help/Help,About.

    There are examples under the Documentation heading but I think they are all written in C and I wish to use Python. I have trawled through loads of helpful websites, but most people are writing for when pyuic has been used to create a Python script from the ui file. I've had a look in that file for ideas, but don't know which statements in it would be needed and what else to add.

    Is there a basic tutorial which would introduce me to this?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You might be interested by this page



  • Thanks SGaist, I think I have looked at all of those now. I have given up on trying to find much information on importing the ui form. The reason I wanted to use that method was because it avoided having to fill my program with the gui statements which would be needed if I used pyuic4 to convert it into Python statements. However I have discovered that I can import the Python file into my program which overcomes the problem, so I have switched to using that method and am making progress.

    I have worked out how to use signals and slots to link the widgets to actions which create code, which is more or less all I need to know:

    bq. Sender_____Signal______Receiver___ Slot
    actionQuit___triggered()__Form_____close()
    

    All I'm confused about, is what to do when there is no suitable receiver+action, in this example I want /Help/About to show a message box, but there is no messagebox widget, so I will have to do that in my Python program.

    bq. Sender______Signal_______ Receiver___Slot
    actionAbout___triggered()___ <receiver>__<slot>  
    

    pyuic4 has created an object (if that's the right term):

    self.menuHelp.addAction(self.actionAbout)
    

    All I now need to do is write an action in my Python program like:

     def actionAbout(self):
                   print 'About has activated'
    

    This doesn't work, but I think it's something like right...

    I'm sure I'm nearly there, as I am capable in other programming languages, it's the starting off that's hard!



  • it's taken me all day to work it out, but all I needed was to change the first line 1) to:

        self.actionAbout.triggered.connect(self.actionAbout)
    

    I'm away now...


  • Lifetime Qt Champion

    Any other problem ?



  • @SGaist Yes! I have now created and published a simple app. I will be making a few improvements to it.

    I have been wondering what the pros and cons are for choosing between importing uic to load the GUI.ui or using pyuic4 to convert the GUI.ui into a .py file.
    The first method is simpler for testing, but the second creates a .pyc file after the first run, so I wonder if that loads the app quicker. It's difficult to do a comparison as other factors are involved. Speeding up the loading would be helpful, are there are other advantages?


  • Lifetime Qt Champion

    Unless your application should be able to create dynamically custom user interface based on ui files, just use pyuic4



  • @SGaist Is there any disadvantage to sticking with the first method though?


  • Lifetime Qt Champion

    I'd say you have to ensure that you also deploy the ui file properly so that it can be found by your application


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.