This seems like such a simple thing, but I can't seem to figure it out. How do I make the button the minimum width. It keeps expanding to the width of the layout I put it in. In the following example, the QPushButton width ends up the same as the 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_())
width = btn.fontMetrics().boundingRect(re.sub('&(?=(?:&&)*[^&])', '', text)).width() + 7
. You can just replace all&
that are followed by an even number of&
. – Taejon