layout->addWidget() 导致 showFullScreen() 出现问题
layout->addWidget() causing problems with showFullScreen()
我在 class 中有一个继承 QMainWindow 的 QDockWidget。这是代码:
#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);
}
代码编译无误,运行无异常。事实上,尽管 Mainwindow 是使用 showMaximized() 显示的,但输出是这样的:
如您所见,应用程序不是全屏。上面也没有最大化按钮。
有趣的是,如果我只从扩展坞中删除一个随机小部件,window 就会完美显示。但是对于我的应用程序,我需要所有的小部件同时显示,并且 window 使用全屏。
我找到了解决办法。我将所有行编辑放在一个组框中,一切正常
我在 class 中有一个继承 QMainWindow 的 QDockWidget。这是代码:
#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);
}
代码编译无误,运行无异常。事实上,尽管 Mainwindow 是使用 showMaximized() 显示的,但输出是这样的:
如您所见,应用程序不是全屏。上面也没有最大化按钮。
有趣的是,如果我只从扩展坞中删除一个随机小部件,window 就会完美显示。但是对于我的应用程序,我需要所有的小部件同时显示,并且 window 使用全屏。
我找到了解决办法。我将所有行编辑放在一个组框中,一切正常