Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make different pages of a QStackedWidget of different sizes?

I have a QStackWidget with 2 pages. One page contains just 2 QLineEdit widget and another page contains a large QTextEdit. Does anyone know how to make one page larger than another so that the window still fits tightly for each page? In the Qt Designer, the QStackWidget has to take the larger size in order to first the QTextEdit, but then the page with the QLineEdit widgets would be way too big.

Thanks

like image 909
Kar Avatar asked Sep 04 '25 17:09

Kar


1 Answers

You can set the size policy of the page that is displayed to QSizePolicy.Preferred and the other ones to QSizePolicy.Ignored. After that call adjustSize to update the sizes. For example when you set the current index to show page1 :

page1.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
page2.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)

stackedWidget.adjustSize()
adjustSize()

And when the other page is shown, set the size policies the other way.

like image 142
Nejat Avatar answered Sep 07 '25 06:09

Nejat