Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Solved] Self contained objects
Forum Updated to NodeBB v4.3 + New Features

[Solved] Self contained objects

Scheduled Pinned Locked Moved Mobile and Embedded
21 Posts 3 Posters 8.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alfah
    wrote on last edited by
    #1

    hello,

    I come again with a yet another question. Are there any self contained object lin Qt. By 'self contained' i mean, those things which can act like a container. I checked out the containers in Qt, but those are linear ones like stack, queue and all. The following is what im trying to achieve.

    I have a form with a lot of buttons, images, vertical layouts, horizontal layouts, grid etc etc. All these put together gives me a calender. I want something which can hold all of these and be able to pass it to another form. If this class ie CalenderForm can return a layout or somethin which i can use it in another form.

    I dont know if this is possible. but is there anything close to what im trying to achieve????

    alfah

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      Layouts and widgets can only be used in one place. They aren't copyable. You can however get the layout or child widget from widget A and apply it to widget B, but that means it will be removed from the first.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alfah
        wrote on last edited by
        #3

        Franzk

        The CalenderForm gives me a final layout with all the buttons and labels and images arranged in QVBoxLayout. As you have said above, this can this be passed to another "form which has a class" and has a tab widget??

        Or did you mean that it can be passed to a tabwidget in the same class??

        alfah

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Franzk
          wrote on last edited by
          #4

          Widgets can be passed anywhere you want. They are pretty much self-contained containers, but they are not copyable.

          "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • A Offline
            A Offline
            alfah
            wrote on last edited by
            #5

            So that means, a class should return some kinda widget right??. Will passing a widget mean that it will be removed from the the first one?
            Have any kind of examples that i can refer to? :(

            1 Reply Last reply
            0
            • EddyE Offline
              EddyE Offline
              Eddy
              wrote on last edited by
              #6

              Hi alfah,

              Yes it is possible to use a QWidget as a class in another form, widget...

              Qt Creator has a nice way of giving that funcitonality to you :
              Menu file > New file or project > Choose for Qt under files and classes on the left and then select on the right : Qt designer form class. Then next and choose as template : widget. the h, cpp and ui files will be set up for you and added to your pro file.

              You can alter your ui file using Designer and you can use your class in any other widget, form, mainwindow, QTabWidget ...

              Qt Certified Specialist
              www.edalsolutions.be

              1 Reply Last reply
              0
              • A Offline
                A Offline
                alfah
                wrote on last edited by
                #7

                hey eddy:)
                was jus wondering why i din see posts from you.

                ok now,
                All the forms in my project are created in the same manner as you have said using the Qt creator. This is what im trying to achieve

                *- I will have a mainTab form with a class. The form would have jus have 3 tabs, Calender, History and Statistics.
                *- My project already has three forms with 3 classes CalenderForm, HistoryForm and StatForm.
                *- Opening each form in each tab( as you mentioned in one of my earlier threads looks like bad GUI programming),so i was thinking if these three forms/classes can give some kinda container/layout with all the widgets, May be then i can put these into each tab in the mainform.

                But the way you suggested would mean i will have to once again open forms in the mainTab right?

                atleast a work around would do.

                alfah

                P.S i know this post is a bit too long

                1 Reply Last reply
                0
                • EddyE Offline
                  EddyE Offline
                  Eddy
                  wrote on last edited by
                  #8

                  [quote author="alfah" date="1312442198"]hey eddy:) was jus wondering why i din see posts from you. [/quote]

                  I was still sleeping ;) It's good to be missed ;)

                  What I suggest to do is make a small compilable program for you including the things you like to do with the QTabWidget, ui files and so on. so you can study it. Ok?

                  Qt Certified Specialist
                  www.edalsolutions.be

                  1 Reply Last reply
                  0
                  • EddyE Offline
                    EddyE Offline
                    Eddy
                    wrote on last edited by
                    #9

                    Ok,

                    here it is : "link ":http://dl.dropbox.com/u/33544011/testAlfah.zip

                    This is what I did :
                    I made a new GUI QDialog based project
                    I opened the ui file and added a QTabWidget to it and a layout.

                    Then I added a class based on a ui : myCalendar
                    I opened the myCalendar.ui file in Qt Creator and added 3 buttons with a layout.
                    Now this class is ready to be used elsewhere.

                    In the constructor of the dialog class I added the following code :
                    @ myCalendar * cal = new myCalendar(); //make an instance of my class
                    QVBoxLayout* lay = new QVBoxLayout(ui->tab); //add a layout
                    lay ->addWidget(cal);@
                    When you run you will see your myCalendar class in the first tab.

                    If you have any questions, please use this example to ask specific questions.

                    Qt Certified Specialist
                    www.edalsolutions.be

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      alfah
                      wrote on last edited by
                      #10

                      im goin through the code. will get back to you :)

                      alfah

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        alfah
                        wrote on last edited by
                        #11

                        ok questions :)

                        1. Dialog class has Qwidget as parent right. now if i have a class named , say , myForm which has QMainWindows as parent. would this be still possible???
                        2. When i run application on C7, it jus fills half the screen, is it cuz Dialog has widget as parent?. Can this be solved by making QMainWindows as the parent of Dialog

                        alfah

                        1 Reply Last reply
                        0
                        • EddyE Offline
                          EddyE Offline
                          Eddy
                          wrote on last edited by
                          #12

                          I think you are mixing up things. parent is not the same as inheriting from...

                          @Dialog::Dialog(QWidget *parent) :
                          QDialog(parent), // this can be a QMainWindow
                          ui(new Ui::Dialog)@

                          The dialog class is derived from QDialog. You could use a QmainWindow for that of course.

                          Qt Certified Specialist
                          www.edalsolutions.be

                          1 Reply Last reply
                          0
                          • EddyE Offline
                            EddyE Offline
                            Eddy
                            wrote on last edited by
                            #13

                            Hi Alfah,

                            You are lucky I came back here. I notice you have added a question in your previous post. Please use the "Post a reply" editor to ask more questions, otherwise we probably will not see them. ;)

                            Anyway about your second question :

                            bq. 2. When i run application on C7, it jus fills half the screen, is it cuz Dialog has widget as parent?. Can this be solved by making QMainWindows as the parent of Dialog

                            I didn't see until now you were using mobile.
                            It's better to use a mobile based project instead of the GUI one I suggested you before. In that case your window will be maximized automatically for you. I tested it with Symbian^3 and the emulator since I don't have a C7. But the general principles you learned are the same.

                            Qt Certified Specialist
                            www.edalsolutions.be

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              alfah
                              wrote on last edited by
                              #14

                              oops sorry :)

                              I tried to create a new application jus like the example with MainWindow.cpp,MainWindow.ui and MainWindow.h and form1.cpp,form1.ui,form1.h.

                              These are of QMainWindow. I have pulled in a tabwidget into MainWindow.ui.
                              The problem is im not able to use tabWidget.
                              u;.tabwidget is not recognized :( :(
                              when ui-> is typed i get only options like centralWidget,MainWindow.

                              So im stuck. Feel like its some silly error

                              :(

                              1 Reply Last reply
                              0
                              • EddyE Offline
                                EddyE Offline
                                Eddy
                                wrote on last edited by
                                #15

                                bq. The problem is im not able to use tabWidget.

                                have you other projects open in Qt Creator? Close them and try to use ui. again. I noticed Qt Creator sometimes looks in other ui files which have been opened.

                                Qt Certified Specialist
                                www.edalsolutions.be

                                1 Reply Last reply
                                0
                                • EddyE Offline
                                  EddyE Offline
                                  Eddy
                                  wrote on last edited by
                                  #16

                                  I have filed a bug report "QTCREATORBUG-5730":https://bugreports.qt.nokia.com/browse/QTCREATORBUG-5730 for this behaviour .

                                  I you encounter that too, please vote for it to get it resolved.

                                  Qt Certified Specialist
                                  www.edalsolutions.be

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    alfah
                                    wrote on last edited by
                                    #17

                                    ahhhhhhhhhhh exactlyy :) i closed and opened the creator and I got the widgets!!!!

                                    got it right :)

                                    annd yeaaaa it runsssssssss :)

                                    now im back to my own project tryin to implement what you've taught :)

                                    thanks

                                    alfah

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      alfah
                                      wrote on last edited by
                                      #18

                                      for voting i can use the same username and password to login??
                                      EDIT: i signed up :)

                                      1 Reply Last reply
                                      0
                                      • EddyE Offline
                                        EddyE Offline
                                        Eddy
                                        wrote on last edited by
                                        #19

                                        Great!

                                        To vote you have to register first. unfortunately you cannot use the same username and password as in the devnet forum.

                                        bq. i closed and opened the creator and I got the widgets!!!!

                                        did you have any other projects open in Qt Creator? I ask to analyse a bit more when this occurs.

                                        And could you please set the title to solved by editing it and adding [Solved] in front of it?

                                        Qt Certified Specialist
                                        www.edalsolutions.be

                                        1 Reply Last reply
                                        0
                                        • A Offline
                                          A Offline
                                          alfah
                                          wrote on last edited by
                                          #20

                                          :) i had the testalfah project opened along with my new project :)
                                          But even after closing the testalfah project I could not get the widgets.

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved