0

I have a horizontal layout inside which i have added a group box. The group box is split using a QSplitter and contain a QListWidget and a QTextBrowser. I want to add two push buttons at the bottom right corner of the window to navigate inside the QTextBrowser. I'm adding two buttons inside the layout but unable to add them at the bottom right corner. Here is my code:

QWidget *www = new QWidget;
QGroupBox*    _groupBox = new QGroupBox();
_groupBox->setTitle("Info");
QVBoxLayout *_verticalLayout = new QVBoxLayout(_groupBox);
www->setLayout(_verticalLayout);
QSplitter *_splitter = new QSplitter(_groupBox);
_splitter->setOrientation(Qt::Horizontal);

QListWidget *_list = new QListWidget(_splitter);
QListWidgetItem *item1 = new QListWidgetItem;
item1->setText("List1 Info");
_list->insertItem(0, item1);
QListWidgetItem *item2 = new QListWidgetItem;
item2->setText("List2 Info");
_list->insertItem(1, item2);
_list->setSelectionMode(QAbstractItemView::SingleSelection);
_splitter->addWidget(_list);

QTextBrowser *_helpBrowser = new QTextBrowser(_splitter);
QPushButton* _homeButton = new QPushButton("home");
QPushButton* _backButton = new QPushButton("back");
QPushButton *_closeButton = new QPushButton("close");

QHBoxLayout *buttonLayout = new QHBoxLayout(this);
buttonLayout->addWidget(_closeButton);
buttonLayout->addStretch(1);
buttonLayout->addWidget(_homeButton);
buttonLayout->addWidget(_backButton);


_splitter->addWidget(_helpBrowser);
_splitter->setStretchFactor(1,1);

_verticalLayout->addWidget(_splitter);

_verticalLayout->addLayout(buttonLayout);//new

www->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
www->resize(1000,600);
www->show();

Adding the HBoxLayout to the VBoxLayout doesnt work well for me. I get a warning that says QLayout::AddChildLayout: layout already has a parent' but displays in correct format. How do i get all the elements correctly positioned without getting the QT Warning?

Edited by myk45

2
Contributors
1
Reply
15
Views
2 Years
Discussion Span
Last Post by Banfa
0

At line 24 remove the this because that makes the current class (window/widget) the parent but line 36 tries to make the _verticalLayout the parent too and causes the warning since the parent is already set.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.