停靠在主窗口右侧时,QDockWidget大小错误 [英] QDockWidget sized wrong when docked on right side of Main Window
问题描述
我是Qt的新手,我正在尝试创建一个停靠在窗口右侧的DockWidget.我为扩展坞设置了最大和最小宽度(如下面的代码所示).如果使用Qt::LeftDockWidgetArea
添加了停靠小部件,则可以使用该功能,但是如果使用Qt::RightDockWidgetArea
添加了停靠小部件,则该停靠将被填充"到窗口的中央,如下所示:
I am new to Qt and I am trying to create a DockWidget that docks on the right of the window. I set a maximum and minimum width for the dock (as you will see in the code below). This works if the dock widget is added with Qt::LeftDockWidgetArea
, but when it is added with Qt::RightDockWidgetArea
, The dock is "padded" out to the center of the window, like this:
我可能没有以正确的方式调整码头的尺寸..这是此窗口的代码:
I am probably not sizing the dock in the correct way.. Here is the code for this window:
int main(int argv, char** args)
{
QApplication app(argv, args);
QMainWindow window;
QDesktopWidget* desktop = QApplication::desktop();
//Docks
QDockWidget* propertyDock = new QDockWidget("",&window);
QWidget* propertyDockContents = new QWidget;
//This sets the window in the center of the screen.
int wWidth = 800; int wHeight = 600;
window.setGeometry(QRect( (desktop->width()-wWidth)/2 , (desktop->height()-wHeight)/2 ,wWidth,wHeight));
propertyDock->setAllowedAreas(Qt::RightDockWidgetArea);
propertyDockContents->setMaximumWidth(200);
propertyDockContents->setMinimumWidth(20);
propertyDock->setWidget(propertyDockContents);
window.addDockWidget(Qt::RightDockWidgetArea,propertyDock);
window.show();
return app.exec();
}
是否有正确"的方法来做到这一点?
Is there a "correct" way to do this?
推荐答案
如文档中所述:
注意:不支持创建没有中央窗口小部件的主窗口.即使它只是一个占位符,也必须有一个中央窗口小部件.
Note: Creating a main window without a central widget is not supported. You must have a central widget even if it is just a placeholder.
这篇关于停靠在主窗口右侧时,QDockWidget大小错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!