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] Help me with creating a Groupbox with listwidget and buttons!
QtWS25 Last Chance

[SOLVED] Help me with creating a Groupbox with listwidget and buttons!

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.9k 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

    Hello. I want to create a groupbox like this:
    !http://img192.imageshack.us/img192/8825/screenshotsra.png(Screen1)!

    With this code:
    @optionsGroupBox = new QGroupBox(tr("Items"));
    optionsGroupBoxLayout = new QGridLayout;
    optionsGroupBoxLayout->addWidget(ui->listWidget, 1, 0);
    optionsGroupBoxLayout->addWidget(ui->addButton, 1, 1);
    optionsGroupBoxLayout->addWidget(ui->editButton, 1, 1);
    optionsGroupBoxLayout->addWidget(ui->removeButton, 1, 1);
    optionsGroupBoxLayout->addWidget(ui->clearButton, 1, 1);
    optionsGroupBoxLayout->addWidget(ui->moveupButton, 1, 1);
    optionsGroupBoxLayout->addWidget(ui->movedownButton, 1, 1);
    optionsGroupBox->setLayout(optionsGroupBoxLayout);@

    I have this:
    !http://img197.imageshack.us/img197/9135/screenshot1st.png(Screen2)!

    All the buttons are in one place now.. I know why.. cause i have set all to 1,1.. but what else could i do? It is something like 1,1,another number here,another one here ... Don't know!

    P.S Another solution would be to make a vertical layout of the buttons and then add the layout to the groupbox .. But how?
    optionsGroupBoxLayout->addLayout(ui->verticalLayout, 1, 1);
    Will give me an error:QLayout::addChildLayout: layout "verticalLayout" already has a parent
    The program has unexpectedly finished.

    Thanks for any answer, Leon :)

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

      Is there a reason you add all the widgets to the same row and column (that is: the same cell in the grid layout)?

      I would probably not use a QGridLayout, but use a QVBoxLayout for the buttons, and a QHBoxLayout to put the listbox and the layout for the buttons in.

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

        Hello andre! Thanks for the tip! It worked :)

        @mainLayout2 = new QHBoxLayout;
        mainLayout2->addWidget(ui->listWidget);
        mainLayout3 = new QVBoxLayout;
        mainLayout3->addWidget(ui->addButton);
        mainLayout3->addWidget(ui->editButton);
        mainLayout3->addWidget(ui->removeButton);
        mainLayout3->addWidget(ui->clearButton);
        mainLayout3->addWidget(ui->moveupButton);
        mainLayout3->addWidget(ui->movedownButton);
        optionsGroupBox = new QGroupBox(tr("Items"));
        optionsGroupBoxLayout = new QGridLayout;
        optionsGroupBoxLayout->addLayout(mainLayout2, 1,0);
        optionsGroupBoxLayout->addLayout(mainLayout3, 1,1);
        optionsGroupBox->setLayout(optionsGroupBoxLayout);@

        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