Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't add widget created by Designer

Can't add widget created by Designer

Scheduled Pinned Locked Moved General and Desktop
12 Posts 4 Posters 7.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.
  • D Offline
    D Offline
    dart505
    wrote on last edited by
    #1

    Hello,

    I've created a widget using Designer (Right Click -> Add new... -> Qt Designer Form)
    It's name is Fuel_widget

    now I'm trying to use it in main window but nothing shows up :(

    here is the code
    @

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "ui_fuel_widget.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    QWidget *f = new QWidget;
    Ui::Fuel_widget u;
    u.setupUi(f);
    

    // This code shows me something look like that i want but I think it's a bad way to do things
    ui->gridLayout->addWidget(u.verticalLayoutWidget);
    // And this one shows nothing
    // ui->gridLayout->addWidget(f);
    }

    @

    I'm a total newbie with Qt so I think the fix will be quite simple.
    Help :)

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Blizzard
      wrote on last edited by
      #2

      Try f.show();

      Software Engineer | Aerospace & Defence

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dart505
        wrote on last edited by
        #3

        f->show(); shows my widget as different window.
        and does only if I didn't added my widget to any of layouts.

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

          You should read the handbook carefully. Usually we can create a class which derived from QWidget or QMainWindow,or something. And define a private member variable Ui::Fuel_Widget *ui. Then use it.
          Fortunately, the Qt Creator will help you make all things to be done.

          Or you can try UiLoader to use a single UI file.

          I just know coding and coding

          1 Reply Last reply
          0
          • F Offline
            F Offline
            foxyz
            wrote on last edited by
            #5

            Run Qt Creator, Use menu "New file or Projects"
            A dialog will show out( choose a template)
            Choose "Qt" under "Files and Classes" at left
            Choose "Qt Designer Form Class" ....

            I just know coding and coding

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dart505
              wrote on last edited by
              #6

              bq. Run Qt Creator, Use menu “New file or Projects”
              A dialog will show out( choose a template)
              Choose “Qt” under “Files and Classes” at left
              Choose “Qt Designer Form Class” ….

              I've made that.
              Now trying to use created class with
              @
              Fuel_widget *f = new Fuel_widget;
              ui->verticalLayout->addWidget(f);
              @

              but nothing happens again :(

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dart505
                wrote on last edited by
                #7

                bq. You should read the handbook carefully. Usually we can create a class which derived from QWidget or QMainWindow,or something. And define a private member variable Ui::Fuel_Widget *ui. Then use it.
                Fortunately, the Qt Creator will help you make all things to be done.

                I've tried that but this doesn't work just like previous variant :(

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  Blizzard
                  wrote on last edited by
                  #8

                  Are you trying to create a multi or single document interface? What I'm asking is do you want your widget to be created in a new window within your mainwindow? If yes, then you need to use an MDI.
                  @
                  QMdiArea *myArea = new QMdiArea;
                  Fuel_widget *f = new Fuel_widget;
                  QMdiSubWindow *myWidgetSubWindow = myArea->addSubWindow(f);
                  @

                  Software Engineer | Aerospace & Defence

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dart505
                    wrote on last edited by
                    #9

                    bq. Are you trying to create a multi or single document interface?

                    no, I'm just trying to draw something I created with QT Designer within my main window couple times. That is why I made widget and trying to add it to main window.
                    Am I doing it wrong?

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      lgeyer
                      wrote on last edited by
                      #10

                      Did you set the widget as the main windows central widget using QMainWindow::setCentralWidget()?

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        dart505
                        wrote on last edited by
                        #11

                        yes, there is such code in 'ui_mainwindow.h' (which is generated by Designer) and it is run when I make mainwindow object (in constructor ui->setupUi(this))

                        why does it matter?

                        1 Reply Last reply
                        0
                        • B Offline
                          B Offline
                          Blizzard
                          wrote on last edited by
                          #12

                          I would recommend reading the "mainwindow documention":http://developer.qt.nokia.com/doc/qt-4.8/QMainWindow.html, and some beginner Qt material - there is a ton available online.

                          This "thread":http://developer.qt.nokia.com/forums/viewthread/8779 might prove useful as well.

                          Software Engineer | Aerospace & Defence

                          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