Pregunta

I tried to create a widget having the following layout:

enter image description here

I tried several approaches, in my first one, I used a QVBoxLayout to that I added different Widgets that used the QGridLayout (so I would get the horizontal resize in the way I want it).

//pseudo code, just to show what I tried... 
myHeaderWidget::myHeaderWidget() {
    QGridLayout* layout = new QGridLayout;

    layout->addWidget(new QCheckBox(), 0, 0, 1, -1, Qt::AlignRight | Qt::AlignTop);
    setLayout(layout);
}


oneOfMyOtherWidgets::oneOfMyOtherWidgets() {
    QGridLayout* layout = new QGridLayout;

    layout->addWidget(new QCheckBox(), 0, 0, 1, 1, Qt::AlignLeft | Qt::AlignTop);
    layout->addWidget(new QPushButton(), 0, 1, 1, -1, Qt::AlignLeft | Qt::AlignTop);

    setLayout(layout);
}


mydialog::mydialog() {
    QVBoxLayout* layout = new QVBoxLayout;
    setLayout(layout);

    layout->addWidget(new myHeaderWidget, 0, Qt::AlignRight);
    //here was the third widget containing Descr1 and Description2, as
    //drawn in image above
    layout->addWidget(new oneOfMyOtherWidgets, 0, Qt::AlignLeft);
}    

The second approach was to use a QGridWidget as layout for mydialog, and my third approach was to add all those items to the same QGridWidget of mydialog.

All those results in the same, for me strange, behavior: At any time I created those dialog and called show(), one of the following could happen:

  1. all items were drawn in the way I wanted.
  2. the checkboxes on the left were shown, but the buttons on the right were covering the description of the checkbox
  3. the checkboxes on the left were correct, but I couldn´t found the buttons.
  4. the buttons took all the space and you couldn´t see any checkboxes at all.

May somebody give me a hint, what I did wrong, or show me a way to create the layout I drew in the image?

¿Fue útil?

Solución

Found it by myself:

setColumnStretch(0,1);

was missing. The added widgets took the whole space in the cell, but the cell never grew.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top