Qt下设置停靠窗口的大小
2013-04-18 10:42
435 查看
A QDockWidget acts as a wrapper for its child widget, set with setWidget(). Custom size hints, minimum and maximum sizes and size policies should be implemented in the child widget. QDockWidget
will respect them, adjusting its own constraints to include the frame and title. Size constraints should not be set on the QDockWidget itself, because they change depending on wether it is docked; a docked QDockWidget has no frame and a smaller title bar.(Come
From English document).
上面的主要意思是说设置停靠窗口的大小不能在QDockWidget中设置,因为他们的改变取决于是否停靠。所以要设置停靠窗口的大小应该在QDockWidget上放置的窗体本s身中设置。
Example:
//set the width in the child form
//in the child form constructor I set the width
//in the main.cpp, I add a dock window of MyWidget instance into the main window
//then you can run the program, you can drag the border of the dock window, you will find that only drag into 400.
will respect them, adjusting its own constraints to include the frame and title. Size constraints should not be set on the QDockWidget itself, because they change depending on wether it is docked; a docked QDockWidget has no frame and a smaller title bar.(Come
From English document).
上面的主要意思是说设置停靠窗口的大小不能在QDockWidget中设置,因为他们的改变取决于是否停靠。所以要设置停靠窗口的大小应该在QDockWidget上放置的窗体本s身中设置。
Example:
//set the width in the child form
//in the child form constructor I set the width
#include "mywidget.h" MyWidget::MyWidget(QWidget *parent) : QWidget(parent) { this->setMaximumWidth(400); }
//in the main.cpp, I add a dock window of MyWidget instance into the main window
#include "mainwindow.h" #include "mywidget.h" #include <QApplication> #include <QDockWidget> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; MyWidget *widget = new MyWidget; QDockWidget *dockWidget = new QDockWidget; dockWidget->setWidget(widget); w.addDockWidget(Qt::LeftDockWidgetArea, dockWidget); w.show(); return a.exec(); }
//then you can run the program, you can drag the border of the dock window, you will find that only drag into 400.
相关文章推荐
- QT_OpenGL设置窗口出事位置和大小
- Qt窗口屏幕居中显示以及设置大小
- Qt 设置窗口居中显示和窗体大小
- WeifenLuo DockContent停靠窗口的大小设置
- QT——设置窗口的固定大小、QProcess、定时器事件、QString::arg、系统时间、QPixmap 和 QImage 区别
- QT怎么设置字体轮廓、字体位置、字体样式、字体间距、窗口背景色大小、隐藏鼠标图标
- Qt窗口屏幕居中显示以及设置大小
- Qt如何设置窗口屏幕居中显示以及设置大小
- Qt设置窗口的初始大小(使用sizeHint这个虚函数,或者在构造函数里使用resize函数)
- QT 设置为固定大小窗口
- Qt窗口屏幕设置大小与居中显示
- Qt 设置窗口居中显示和窗体大小
- QT中设置窗口大小和居中部
- Qt窗口大小设置
- Qt停靠窗口角落设置
- Qt控件随窗口大小变化的设置方法(QTDesigner)
- QT 设置为固定大小窗口
- Qt控件随窗口大小变化的设置方法(QTDesigner)
- QT5 设置按钮图标自适应大小
- Qt软件开发文档15---聊天窗口的实现(2),QTextEdit+QPainter实现聊天框自适应大小