Luc PHAN
Luc PHAN

Reputation: 310

QFormLayout: Label column truncated on resize

When I resize my QFormLayout, the label column disappears.

Here is my layout:

Form description

label = QLabel("I don't want to be truncated!")

horizontal_layout = QHBoxLayout()
for i in range(5):
    button = QPushButton(str(i))
    horizontal_layout.addWidget(button)

form_layout = QFormLayout()
form_layout.addRow(label, horizontal_layout)

On resize:

Label gone

Why is that column hidden? There should be enough place to display it, because the buttons width can be very small. Here is their minimum size:

Minimum size

In my true program, the label column is truncated. I tried to reproduce the problem, but I failed. However, a disappearing column is almost the same problem.

Full source code:

import sys
from PyQt4.QtGui import QApplication, QWidget, QFormLayout, QHBoxLayout,\
    QPushButton, QLabel


class Form(QWidget):
    def __init__(self):
        QWidget.__init__(self)

        label = QLabel("I don't want to be truncated!")

        horizontal_layout = QHBoxLayout()
        for i in range(5):
            button = QPushButton(str(i))
            horizontal_layout.addWidget(button)

        form_layout = QFormLayout()
        form_layout.addRow(label, horizontal_layout)
        self.setLayout(form_layout)

        self.setMinimumWidth(1)

application = QApplication(sys.argv)
form = Form()
form.show()
application.exec_()

Upvotes: 0

Views: 900

Answers (1)

a_manthey_67
a_manthey_67

Reputation: 4286

if this line

self.setMinimumWidth(1)

is replaced by

button.setMinimumWidth(1)

as second line in the for loop it works

Upvotes: 2

Related Questions