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. [SOLVED] MainWindow has already a Layout, what can i do for this?

[SOLVED] MainWindow has already a Layout, what can i do for this?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.0k Views
  • 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.
  • L Offline
    L Offline
    Leon
    wrote on last edited by
    #1

    When trying to do this is a mainwindow a get an error that the mainwindow has already a layout.. (If u want the excact error i will reproduce it )

    @ mainLayout = new QVBoxLayout;
    mainLayout->addWidget(optionsGroupBox);
    mainLayout->addLayout(buttonsLayout);
    setLayout(mainLayout);@

    P.S This happens only to mainwindow.. i am capable of doing it in every other dialog..

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Use setCentralWidget() instead to provide QMW with a "main" object.

      (Z(:^

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sam
        wrote on last edited by
        #3

        The QMainWindow has a centralWidget so one option is to set the layout to a widget/frame and then you can use setCentralWidget().

        @mainLayout = new QVBoxLayout;
        mainLayout->addWidget(optionsGroupBox);
        mainLayout->addLayout(buttonsLayout);
        QWidget *widget = new QWidget();

        widget->setLayout(mainLayout);
        setCentralWidget(widget);@

        see "Qt Main Window Framework":http://qt-project.org/doc/qt-5.0/qmainwindow.html#details

        1 Reply Last reply
        0
        • L Offline
          L Offline
          Leon
          wrote on last edited by
          #4

          I forgot to say thank you and solved! :)

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sam
            wrote on last edited by
            #5

            U r Welcome :)

            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