Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to include one widget in another?
Qt 6.11 is out! See what's new in the release blog

How to include one widget in another?

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 3.7k 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
    aurora
    wrote on last edited by
    #1

    I created two widget one by command another by Qt form designer. The code as shown below. When i execute two separates forms displays....What changes do i need to do, so that one form displays inside another form as single widget?

    fileopen.cpp
    @
    fileopen::fileopen(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::fileopen),
    m_layout( new QVBoxLayout() )
    {

    QPushButton* add = new QPushButton("Add");
    
    connect(add, SIGNAL(clicked()), this, SLOT(addRow()));
    

    m_layout->addWidget(add);
    m_layout->setAlignment(Qt::AlignTop);

    QWidget* w = new QWidget();
    w->setLayout(m_layout);
    

    w->show();

    ui->setupUi(this);
    

    }
    @

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

      I think you need:
      @
      this->setCentralWidget(w);

      • ui->setupUi(this);
      • ui->setupUi(this->centralWidget());

      }
      @

      "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
        aurora
        wrote on last edited by
        #3

        [quote author="Franzk" date="1320225013"]I think you need:
        @
        this->setCentralWidget(w);

        • ui->setupUi(this);
        • ui->setupUi(this->centralWidget());

        }
        @[/quote]

        hmmm...sorry got a compiler error saying that..:
        error: invalid conversion from 'QWidget*' to 'QMainWindow*'
        error: initializing argument 1 of 'void Ui_fileopen::setupUi(QMainWindow*)'

        both error message pointing ui->setupUi(this->centralWidget());

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          You need to set the parent argument to the widget you want have the new widget contained in. If you use a layout correctly, then that is what happens as well. In your current code, w has a layout, but is not in a layout.

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

            Ah right, I think I misunderstood the issue.

            "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
            • F Offline
              F Offline
              Franzk
              wrote on last edited by
              #6

              Just as an extra remark, I think I would create a separate widget for the central area. It could depend on the type of application though.

              "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

              • Login

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