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



  • 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 :)



  • 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.



  • 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);@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.