How to create a "corner" widget with Qsplitter or so

  • Hi all,

    I'd like to obtain a layout in which I have 2 widgets of which one is placed in a corner, see the image below:

    ! layout)!

    Ideally, the 2 red lines would be QSplitter, so that the corner widget would be resizable.
    Is it possible to obtain such a layout??
    thank you.

  • You mean two overlapping widgets? Then you should check out "QStackedLayout": and set the QStackedLayout::StackingMode to QStackedLayout::StackAll.

    QStackedLayout* mainLayout = new QStackedLayout;
    mainLayout->setStackingMode( QStackedLayout::StackAll );

    QWidget* greaterWidget = new QWidget;
    mainLayout->addWidget( greaterWidget );

    QWidget* cornerWidget = new QWidget;
    QWidget* alignmentWidget = new QWidget;
    QGridLayout* alignmentLayout = new QGridLayout( alignmentWidget );
    alignmentLayout->addWidget( cornerWidget, 0, 0, Qt::AlignRight | Qt::AlignBottom );

    mainLayout->addWidget( alignmentWidget );
    mainLayout->setCurrentWidget( alignmentWidget );

    The alignmentWidget is needed to position the corner widget at the bottom-right, since QStackedLayout's insertWidget function doesn't allow for specifying the alignment of the widget being added.

  • Hi Napaje,

    thanks for your hint.
    I'm probably missing something to have your code working on my side.
    I had to add a Box Layout above the Stacked one to see something appear.
    But it works only when I use StackOne, when I use StackAll and add the 2 widgets (greater and corner) I get nothing.
    I've also tried to specify manually the geometry of the cornerWidget but nothing changes.

    Anyway I got the idea, but in the configuration you suggest would the red borders be movable, so to allow the cornerWidget to be resized?

    Thank you!

Log in to reply

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