简体   繁体   English

PyQt5进度条填充整个QGroupBox吗?

[英]PyQt5 Progress bar to fill the whole QGroupBox?

I am trying to get a progress bar to fill the whole width of a QGroupBox. 我正在尝试获取进度条以填充QGroupBox的整个宽度。

So far it looks like: 到目前为止,它看起来像:

进展

I am trying to get it to go all the way across. 我正在努力使其一路过关斩将。 Here is the code: 这是代码:

def progress(self):
    gBox = QGroupBox('Progress')
    progress_bar = QProgressBar(gBox)
    progress_bar.setRange(0, 1)
    # progress_bar.setGeometry(30, 40, 200, 25)

    hbox = QHBoxLayout()
    hbox.addWidget(progress_bar)
    hbox.addStretch(1)
    gBox.setLayout(hbox)
    return gBox

Do I need to stretch the QGroupBox or the QHBoxLayout? 我是否需要拉伸QGroupBox或QHBoxLayout?

According to the docs : 根据文档

void QBoxLayout::addStretch(int stretch = 0) 无效的QBoxLayout :: addStretch(int Stretch = 0)

Adds a stretchable space (a QSpacerItem) with zero minimum size and stretch factor stretch to the end of this box layout. 在此框布局的末尾添加最小大小为零且拉伸因子拉伸为零的可拉伸空间(QSpacerItem)。

That is, a spacer is added, that spacer is added to the end, so it pushes the widget to take the size of sizeHint() compressing it. 也就是说,添加了一个隔离符,该隔离符被添加到末尾,因此它推动小部件以sizeHint()的大小压缩它。

In your case you do not need it, so remove it. 在您的情况下,您不需要它,因此将其删除。

def progress(self):
    gBox = QGroupBox('Progress')
    progress_bar = QProgressBar(gBox)
    progress_bar.setRange(0, 1)

    hbox = QHBoxLayout()
    hbox.addWidget(progress_bar)
    gBox.setLayout(hbox)
    return gBox

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

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