简体   繁体   English

在 PyQt5 中调整停靠小部件的大小

[英]Resize docked widgets in PyQt5

I have a main window of my app and two other widgets, that are docked to the right side of the main window.我的应用程序有一个主 window 和另外两个小部件,它们停靠在主 window 的右侧。 How could I resize the two docked widgets?如何调整两个停靠的小部件的大小? 在此处输入图像描述

"Date" and "Time" widgets must be resized so that they both vertically take half of the space, and horizontally must be both wider. “日期”和“时间”小部件必须调整大小,以便它们在垂直方向上占据一半空间,在水平方向上都必须更宽。

Here is how I create the window and the widgets:以下是我创建 window 和小部件的方法:

def __init__(self):
    super().__init__()

    self.resize(2000, 1200)
    self.center()
    self.setWindowTitle("ARMS")

    self.date = QDockWidget("Date", self)
    self.time = QDockWidget("Time", self)

    self.dateWidget = QWidget()

    self.timeWidget = QListWidget()
    self.timeWidget.addItems(['0', '3', '6', '9', '12', '15', '18', '21'])

    self.date.setWidget(self.dateWidget)
    self.date.setFloating(False)

    self.time.setWidget(self.timeWidget)
    self.time.setFloating(False)

    self.setCentralWidget(QTextEdit())
    self.addDockWidget(Qt.RightDockWidgetArea, self.date)
    self.addDockWidget(Qt.RightDockWidgetArea, self.time)

I've tried the following, but it didn't work:我尝试了以下方法,但没有奏效:

self.date.resize(800, 1000) 
# and
self.dateWidget.resize(800, 1000)

Also, is there a way to make those two widgets undraggable and unclosable;另外,有没有办法让这两个小部件不可拖动和不可关闭? just lock them at place the way they are?只是按原样锁定它们?

Thanks to @ekhumoro,感谢@ekhumoro,

QMainWindow.resizeDocks and QDockWidget.setFeatures are the answer. QMainWindow.resizeDocksQDockWidget.setFeatures就是答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM