PDA

View Full Version : yet another sizePolicy prob: how can I get a QTextBrowser to scale with its QTabWidg



plipson
7th March 2011, 20:33
My mainWindow has a centralWidget with a QTabWidget filling it; I want one of the tab pages to have a stretchable widget filling it as well. I haven't been able to get it to work with QT designer, even when I hand-edit the XML file to ensure I have the structure I want.
It seems that the solution should be to set the SizePolicy property correctly, but even though I've put either "Ignored" or "Expanding" on each QWidget, and tried setting the horstretch attributes, it won't stretch. I'm using CTRL-R within QTDesigner to check it.
I see other posts similar to this, but none seem to have any answer. I'm attaching a tiny demo UI file, too.

SixDegrees
7th March 2011, 21:15
You need to place widgets in a layout if you want sizing behavior to be honored.

plipson
7th March 2011, 23:23
that was a good hint - though it's a bit trickier than that. I had already been nesting layout/widget/layout as I built it.
For others with this problem, here's the 'fix' (Here's a sample UI) too:

if you look into the first UI file you'll see this:

<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="centralLayout">
<item>
<widget class="QTabWidget" name="tabBoyWidget">
<widget class="QWidget" name="tab_the_first">
<widget class="QWidget" name="tab1layoutWidg">
<layout class="QVBoxLayout" name="tabOneLayout">
<item>
<widget class="QTextBrowser" name="textBrowser">

=====================
the problem is the <widget ...> <widget ...><widget ...> <layout ...><item><widget> - For some reason, QT Designer wants to add an extra layer of QWidget. It has to be removed with a text editor, outside of QTDesigner.
For example:
once it's working, and I want to add a page:
Using QT Designer, right-click and add a page. Put the layout in the new page, and add a widget to it. Save and close.
Open in a text editor. You'll find a new <widget name="tab"><attribute><widget name = "...layoutWidget"><property><layout....><item>
Delete the <widget> between the <attribute> and <property> tags (and its </widget>) and re-open in QT Designer. Now it'll respect its sizePolicy.