PyQt5:如何对齐状态栏的元素? [英] PyQt5: How to align the elements of the status bar?

查看:122
本文介绍了PyQt5:如何对齐状态栏的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个如下所示的状态栏:

I've created a status bar which looks like this:

def initStatusbar(self):
    self.zoomSlider = QSlider(Qt.Horizontal)
    self.zoomSlider.setMaximumWidth(200)
    self.zoomSlider.setRange(1, 200)
    self.zoomSlider.setSingleStep(10)
    self.zoomSlider.setValue(100)

    self.progressbar = QProgressBar()
    self.progressbar.setMaximumWidth(400)
    self.statusBar().addWidget(self.progressbar)
    self.statusBar().addWidget(self.zoomSlider)

截图如下:

但我想像截图一样替换进度条和滑块:

But I want to replace the progress bar and the slider like in that screenshot:

推荐答案

最初的解决方案是使用大于零的拉伸,但这会使 QProgressBar 拉伸无限制,在这种情况下最好将其包含在另一个小部件并将其嵌入到 QStatusBar 中.

An initial solution would be to use a stretch greater than zero, but this would make the QProgressBar stretch without limits, in this case it is best to include it inside another widget and embed this in the QStatusBar.

def initStatusbar(self):
    self.zoomSlider = QSlider(Qt.Horizontal)
    self.zoomSlider.setMaximumWidth(200)
    self.zoomSlider.setRange(1, 200)
    self.zoomSlider.setSingleStep(10)
    self.zoomSlider.setValue(100)

    self.progressbar = QProgressBar()
    self.progressbar.setMaximumWidth(400)

    widget = QWidget(self)
    widget.setLayout(QHBoxLayout())
    widget.layout().addWidget(self.progressbar)
    widget.layout().addWidget(self.zoomSlider)
    self.statusBar().addWidget(widget, 1)

截图:

这篇关于PyQt5:如何对齐状态栏的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆