gpt4 book ai didi

python - 在 QVBoxLayout 中添加 QStatusBar

转载 作者:行者123 更新时间:2023-11-28 21:21:20 26 4
gpt4 key购买 nike

我需要在 QVBoxLayout 中的表格下方添加一个状态栏。问题是我不知道为什么不显示状态栏。在QBoxLayout中,我添加了一个tableView,在表格下面我需要有状态栏。这是我的部分代码:

  self.setGeometry(200,200,600,600)
if self._model.productName()!='':
self.setWindowTitle('TITLE')
QVBoxLayout(self).addWidget(self.tv)

# add staus bar
statusBar = QStatusBar()
statusLabel = QLabel("Here comes the status bar message!!")
statusBar.addWidget(statusLabel)
QVBoxLayout(self).addWidget(statusBar)

最佳答案

显示状态栏的理想方式是首先继承QtGui.QMainWindow 类,然后使用statusBar 方法创建状态栏。

所以在创建 GUI 的主类中,您可以这样做:

class Window(QtGui.QMainWindow):
def __init__(self, parent):
super(Window, self).__init__()
self.statusbar = self.statusBar()

然后您可以按以下方式在状态栏中显示消息:

self.statusbar.showMessage('This message will be shown in the status bar')

不需要使用 QLabel 来显示状态栏消息。

或者,您可以从 QtGui.QWidget 类继承并执行此操作:

self.statusbar = QStatusBar()
self.statusbar.showMessage('Some status bar message')

另外,作为 one of the other answers指出,您对布局的创建方式有误。

self.layout = QVBoxLayout(self)
self.layout.addWidget(self.tv)

这应该是正确的做法。

关于python - 在 QVBoxLayout 中添加 QStatusBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21673912/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com