P
P
pornstar982019-03-10 20:42:21
Python
pornstar98, 2019-03-10 20:42:21

How to set widget size as a percentage in PyQt5?

I want the widget to be 20% long and 100% high

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bbkmzzzz, 2019-03-10
@pornstar98

As a percentage of what?
For widgets in the layout set strech parameters

widg1.setHorizontalStretch(1)
widg2.setHorizontalStretch(2)

Inside the layout, the sizes of the widgets widg1 and widg2 will be determined by the ratio of the numbers specified in setHorizontalStretch, in this case, the horizontal sizes will be 1 to 2. widg 1 will be 2 times smaller than the second widget
It is desirable to set SizePolicy as Preferred

A
Andrey_Dolg, 2019-03-11
@Andrey_Dolg

In addition, you can play around with QSS styles.
As an example

checkbutton.setStyleSheet("QPushButton {background-color:rgb(0,200,0) ; color: White; border-radius: 3px; height:15%; width:70%} "
                                  "QPushButton:pressed {background-color:rgb(0,150,0) ; }")

But the primary layout by region is above all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question