I have a QDockWidget inside a class that inherits QMainWindow. This is the code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDockWidget>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QRadioButton>
#include <QPushButton>
#include <QCheckBox>
#include <QGroupBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
createDock();
this->showMaximized();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::createDock()
{
//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);
//dock->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
//make group boxes
QWidget *filters = new QWidget(this);
//only show book which are not returned yet
QCheckBox *notReturnedOnly = new QCheckBox("Only Show books which are not returned");
layout->addWidget(notReturnedOnly);
createHistory();
createIssuedBy();
createBookIssued();
createClassGroup();
createRack();
createPublisher();
//resetFilters
QPushButton *resetFilters = new QPushButton("Reset Filters");
layout->addWidget(resetFilters, 0, Qt::AlignCenter);
filters->setLayout(layout);
dock->setWidget(filters);
this->addDockWidget(Qt::RightDockWidgetArea, dock);
dock->show();
}
void MainWindow::createHistory()
{
//history group box
QGroupBox *history = new QGroupBox("History");
QRadioButton *today = new QRadioButton("Today");
QRadioButton *thisWeek = new QRadioButton("This week");
QRadioButton *thisMonth = new QRadioButton("This Month");
//set auto exclusive
today->setAutoExclusive(false);
thisWeek->setAutoExclusive(false);
thisMonth->setAutoExclusive(false);
//add widgets to history
QVBoxLayout *historyLayout = new QVBoxLayout;
historyLayout->addWidget(today);
historyLayout->addWidget(thisWeek);
historyLayout->addWidget(thisMonth);
history->setLayout(historyLayout);
layout->addWidget(history);
}
void MainWindow::createIssuedBy()
{
//Issued by group box
QGroupBox *issuedBy = new QGroupBox("Issued by");
QLineEdit *student = new QLineEdit;
QHBoxLayout *issuedByLayout = new QHBoxLayout;
issuedByLayout->addWidget(student);
issuedBy->setLayout(issuedByLayout);
layout->addWidget(issuedBy);
}
void MainWindow::createBookIssued()
{
//book issued group box
QGroupBox *bookIssued = new QGroupBox("Book Issued");
QLineEdit *book = new QLineEdit;
QHBoxLayout *bookIssuedLayout = new QHBoxLayout;
bookIssuedLayout->addWidget(book);
bookIssued->setLayout(bookIssuedLayout);
layout->addWidget(bookIssued);
}
void MainWindow :: createClassGroup()
{
QGroupBox *classFilter = new QGroupBox("Class");
QLineEdit *Class = new QLineEdit;
QHBoxLayout * classFilterLayout = new QHBoxLayout;
classFilterLayout->addWidget(Class);
classFilter->setLayout(classFilterLayout);
layout->addWidget(classFilter);
}
void MainWindow :: createPublisher()
{
QGroupBox *publisherFilter = new QGroupBox("Publisher");
QLineEdit *publisher = new QLineEdit;
QHBoxLayout *publisherLayout = new QHBoxLayout;
publisherLayout->addWidget(publisher);
publisherFilter->setLayout(publisherLayout);
layout->addWidget(publisherFilter);
}
void MainWindow :: createRack()
{
QGroupBox *rackFilter = new QGroupBox("Rack Number");
QLineEdit *rack = new QLineEdit;
QHBoxLayout *rackLayout = new QHBoxLayout;
rackLayout->addWidget(rack);
rackFilter->setLayout(rackLayout);
layout->addWidget(rackFilter);
}
The code is compiled without errors and runs without exceptions. Just the fact that even though, the Mainwindow is shown using showMaximized(), the output is like this:
As you can see, the application is not full screen. Neither has the maximize button on it.
Interestingly, if I remove just one random widget from the dock, the window shows up perfectly. But for my application, I need all the widgets to show up at once and the window to be using the full screen.
I found my way around. I placed all the line edits in a single group box and everything works well