这似乎是一件很简单的事情,但我似乎无法弄清楚。如何使按钮的最小宽度。它不断扩展到我放入的布局的宽度。在下面的示例中,QPushButton 的宽度最终与 QLabel 相同:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
class MyWindow(QWidget):
def __init__(self,parent = None):
QWidget.__init__(self,parent)
layout = QVBoxLayout()
layout.addWidget(QLabel('this is a really, really long label that goes on and on'))
layout.addWidget(QPushButton('short button'))
self.setLayout(layout)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec_())