How to use QSizePolicy to fix height of QTextEdit in QVBoxLayout?

147 views Asked by At

I am building an application in which I have implemented a feedback space for error and success messages in a scrollable QTextEdit widget. The QTextEdit widget creates a log-like similar output and I need to show only two-three lines instead of it taking almost half of the window.

The current output looks like this Large QTextEdit

I have been researching a bit QSizePolicy Doc but could not completely understand how to set the QSizePolicy to get the desired output.

Here is my current UI code for this window. Any help or guidance is greatly appreciated. Thanks.

def UI(self):
        #UI LAYOUT
        central_widget = QWidget()
        self.setCentralWidget(central_widget)

        self.scroll = QScrollArea()
        self.scroll.setWidgetResizable(True)
        self.scroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)

        self.console_out = QTextEdit(self)
        print(self.console_out.sizeHint())
        self.console_out.setSizePolicy(QSizePolicy.Minimum, (QSizePolicy.ShrinkFlag | QSizePolicy.Fixed))
        # self.console_out.setMinimumHeight(20)
        self.console_out.setReadOnly(True)
        self.console_out.setPlaceholderText('Plugin Ready!')

        self.scroll.setWidget(self.console_out)

        main_layout = QVBoxLayout(central_widget)

        #NORTH STAR
        ico = QPixmap(cwd + "/ico/north.png")
        self.na = QGraphicsPixmapItem(ico)
        self.na.setTransform(QTransform.fromScale(0.1, 0.1), True)
        self.na.setTransformOriginPoint(self.na.boundingRect().center())
        self.canvas.scene().addItem(self.na)
        self.canvas.scene().update()
        #ROTATION
        self.rot = QSpinBox(self)
        self.rot.setRange(0.0, 360.0)
        self.rot.setSuffix(" °")
        self.rot.valueChanged.connect(self.rotateMapCanvas)

        self.bottom_split = QSplitter(Qt.Horizontal)
        self.bottom_split.addWidget(self.scroll)
        self.bottom_split.addWidget(self.rot)
        self.bottom_split.setStretchFactor(0, 10)

        main_split = QSplitter(Qt.Vertical)
        main_split.addWidget(self.canvas)
        main_split.addWidget(self.bottom_split)
        # main_split.setStretchFactor(100, 1)

        main_layout.addWidget(main_split)
0

There are 0 answers