如何使用代码将 QDockWidgets 定位为屏幕截图所示?
我希望 Qt 窗口在右侧显示以下停靠小部件的排列。
替代文本 http://img72.imageshack.us/img72/6180/docksonside.png< /a>
Qt 允许您向 QMainWindow 的 addDockWidget 方法提供参数来指定位置(上、下、左或右),但显然不是两个 QDockWidgets
放置在同一侧将会被排列。
这是添加停靠小部件的代码。这使用 PyQt4,但对于带有 C++ 的 Qt 来说应该是相同的。
self.memUseGraph = mem_use_widget(self)
self.memUseDock = QDockWidget("Memory Usage")
self.memUseDock.setObjectName("Memory Usage")
self.memUseDock.setWidget(self.memUseGraph)
self.addDockWidget(Qt.DockWidgetArea(Qt.RightDockWidgetArea),self.memUseDock)
self.diskUsageGraph = disk_usage_widget(self)
self.diskUsageDock = QDockWidget("Disk Usage")
self.diskUsageDock.setObjectName("Disk Usage")
self.diskUsageDock.setWidget(self.diskUsageGraph)
self.addDockWidget(Qt.DockWidgetArea(Qt.RightDockWidgetArea),self.diskUsageDock)
当使用此代码将它们都添加到右侧时,一个在另一个之上,不像我制作的屏幕截图。我制作该镜头的方法是在启动程序后用鼠标将它们拖到那里,但我需要它以这种方式启动。
I want a Qt window to come up with the following arrangement of dock widgets on the right.
alt text http://img72.imageshack.us/img72/6180/docksonside.png
Qt allows you to provide an argument to the addDockWidget
method of QMainWindow
to specify the position (top, bottom, left or right) but apparently not how two QDockWidgets
placed on the same side will be arranged.
Here is the code that adds the dock widgets. this uses PyQt4 but it should be the same for Qt with C++
self.memUseGraph = mem_use_widget(self)
self.memUseDock = QDockWidget("Memory Usage")
self.memUseDock.setObjectName("Memory Usage")
self.memUseDock.setWidget(self.memUseGraph)
self.addDockWidget(Qt.DockWidgetArea(Qt.RightDockWidgetArea),self.memUseDock)
self.diskUsageGraph = disk_usage_widget(self)
self.diskUsageDock = QDockWidget("Disk Usage")
self.diskUsageDock.setObjectName("Disk Usage")
self.diskUsageDock.setWidget(self.diskUsageGraph)
self.addDockWidget(Qt.DockWidgetArea(Qt.RightDockWidgetArea),self.diskUsageDock)
When this code is used to add both of them to the right side, one is above the other, not like the screen shot I made. The way I made that shot was to drag them there with the mouse after starting the program, but I need it to start that way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 QMainWindow::splitDockWidget 。
来自文档:
您必须首先将 QMainWindow::dockNestingEnabled 设置为 true (但是我猜你已经这么做了)。
You can use QMainWindow::splitDockWidget .
From the docs:
You have to set QMainWindow::dockNestingEnabled to true first (but I guess you already did that).
我从未尝试过,但我认为您可以在将停靠小部件添加到主窗口时设置它的方向:
void QMainWindow::addDockWidget ( Qt::DockWidgetArea 区域, QDockWidget * dockwidget, Qt::Orientation 方向 )
I never tried it but I think you can set the orientation of the dock widget when adding it to the main window:
void QMainWindow::addDockWidget ( Qt::DockWidgetArea area, QDockWidget * dockwidget, Qt::Orientation orientation )