layout->addWidget() creating problems with full screen
Rahem027 last edited by Rahem027
I have a dock widget with a bunch of line edits and radio buttons. This is my create dock function which creates and shows the dock:
//initialize main layout of dock layout = new QVBoxLayout; //initialize dock QDockWidget *dock = new QDockWidget("Filters", this); dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); dock->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable); //make group boxes QWidget *filters = new QWidget(this); //only show book which are not returned yet notReturnedOnly = new QCheckBox("Only Show books which are not returned"); connect(notReturnedOnly, &QCheckBox::clicked, this, &LogWindow::onNotReturnedClicked); layout->addWidget(notReturnedOnly); createHistory(); createIssuedBy(); createBookIssued(); createClassGroup(); createRack(); createPublisher(); //resetFilters resetFilters = new QPushButton("Reset Filters"); connect(resetFilters, &QPushButton::clicked, this, &LogWindow::reset); layout->addWidget(resetFilters, 0, Qt::AlignCenter); filters->setLayout(layout); dock->setWidget(filters); this->addDockWidget(Qt::RightDockWidgetArea, dock); dock->show();
This is my createRack() function definition:
QGroupBox *rackFilter = new QGroupBox("Rack Number"); rack = new QLineEdit; QHBoxLayout *rackLayout = new QHBoxLayout; rackLayout->addWidget(rack); rackFilter->setLayout(rackLayout); //layout->addLayout(tempLayout); connect(rack, &QLineEdit::editingFinished, this, &LogWindow::onRackNumberEntered); completeRack = new QCompleter(rackModel); completeRack->setCaseSensitivity(Qt::CaseInsensitive); completeRack->setCompletionColumn(0); rack->setCompleter(completeRack);
The window is shown using `this->showMaximized() .
If I uncomment the line:
The window shows up like this: 0_1529479971612_screenshot.png .
Interestingly, If I remove any one widget from the dock, the program runs perfectly fine.
Hi @Rahem027 ,
In some cases, it is relevant when a layout is added to a widget. When you set the widget of a QDockWidget or a QScrollArea (with QDockWidget::setWidget() and QScrollArea::setWidget()), the layout must already have been set on the widget. If not, the widget will not be visible.
This might helpful to you.
@Prince_0912 I didnt get you
Prince_0912 last edited by
@Rahem027 You have to set layout size policy before adding widgets to layout.
@Prince_0912 No. Which one should I use?
@Rahem027 I had same problem as your but i solve this in different manner.
I take one button and one groupbox.
in loading form i hide by,
in button click event i put,
See the property window in this photo.
Rahem027 last edited by Rahem027
From what I interpreted, I set the size policy of my dockWidget: horizontal is now fixed and vertical, i set to expanding. But the window remains the same.
PS: forgive me if I didn't understand what you said.
In my case initially my GroupBox is hide by setting
After that when i click on Mirror Button then GroupBox is appear on display. for that on click function i put,
if you click again in button then GroupBox is hide.
last for the sizepolicy i send you last one photo see ,
parameter of SizePolicy , minimumSize , MaximumSize what i set there.
Cant everything be shown at once? It is important