How to make a QTextEdit fill its parent dialog? - qt

I've been using Qt for some times, but I'm quite new to layouts. I would like to create a dialog with a QTextEdit inside, and the QTextEdit would resize to fill the whole dialog. How can I use layouts to do that? Or is there some other technique that I'm missing?
I have tried adding a layout to the dialog, then put the QTextEdit inside. However, I cannot find any property to make the layout fit the whole dialog.

After adding the text edit to your form, right click on the form and you will see a "Lay out" menu item at the bottom of the context menu, select that and then the layout type you want to use. The designer will create a top level layout of that type for your form and the text edit should now expand to fill the form.

Related

Widget or layout to fill parent

What I'm trying to accomplish is a very simple and straight forward need, or I thought, but for the life of me, I can't seem to find a way to do it.
In my qt application I want to be able to make a widget or a layout fill the entire space of the parent widget.
For example, let's say I want to have a label with a fixed height and beneath it a stacked widget which occupies the rest of the height of the window.
Here's what I do in the qt-creator designer:
drag a label to the form
drag a stacked widget to the form
select both of them and then right click > lay out > lay out vertically
select the verticalLayout object and in the layoutStretch property have 0,1
Now, how do I make the verticalLayout occupy all of the width/height of the centralWidget?
Nothing seems to work for me.
Thanks.
You've merely put two widgets in a layout, but you also need a layout on their parent widget - on the form. Here's what you should do instead:
Drag any number of widgets to the parent widget (the form). Arrange them roughly the way you want them to be once laid out.
Right click on the form. Select "Lay out >" submenu.
Choose the desired layout from the menu: horizontal, vertical, grid, etc.

Qt-designer: enlarging the window does not replace my items

To keep the question as simple as possible, I prepared a simple Qt designer form below
There is a Tab Widget on the left side and empty QWidget on the right side, the QWidget as a GroupBox. The Groupbox has a radio and pusbuttons (you can see them on Object inspector window on the photo as well ). The tab widget has a line edit. The central widget has a gridlayout and horizontal qsplitter is used.
My issue is that when I enlarge the window, all items (lineedit, radiobutton, pushbutton) are on the fix position. Here is an example what I mean:
What I want is that when the window is enlarged the items should be placed on the bottom of the window, or if they are in the middle, then they should stay in the middle. ( I don't want size of the buttons/lineedits to be changed).
How can I do it?
The items you want to move dynamically, with window resizing must be in a layout.
So, in the example you've posted, you need two layouts; one inside the tab widget, for the QLineEdit and at least one in the GroupBox for the radio button and push button.
If you want the radio and push button to be aligned horizontally, you can start by placing them in a horizontal layout, before placing that layout in another, which all reside in the group box.
When you start to add items to layouts, such as push buttons, you'll start to notice that they can get stretched, so you may need to set the size policies of the widgets.
If you want the line edit to be centered horizontally, you will have to place two horizontal spacers on each side of the line edit and select the three together and set "Lay out Horizontally". This can found at the top toolbar in Qt Designer.
To always have it at the bottom of the tab widget, put a vertical spacer above the line edit in your tab widget. Then select the option "Lay out vertically" for the tab widget.
The same goes for your radio button and push button. Keep them in a horizontal layout, with horizontal spacers if required and put a vertical spacer into the group box and set the layout property for the group box as "Lay out Vertically".
Most important of all, I suggest you go through some basic tutorials before you continue. Here is a link to a good channel on youtube.
https://www.youtube.com/playlist?list=PL2D1942A4688E9D63
If you don't have a layout in your tabWidget or GroupBox:
You must set a layout (for example QVBoxLayout) inside your tab widget and a group box.
It can be done using QtDesigner. It also can be done in code like this:
QWidget *window = new QWidget;
QPushButton *button1 = new QPushButton("One");
QPushButton *button2 = new QPushButton("Two");
QPushButton *button3 = new QPushButton("Three");
QPushButton *button4 = new QPushButton("Four");
QPushButton *button5 = new QPushButton("Five");
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
layout->addWidget(button3);
layout->addWidget(button4);
layout->addWidget(button5);
window->setLayout(layout);
But if you do, and then you want your buttons to stay at the bottom:
Then you have to try setRowStretch method http://qt-project.org/doc/qt-4.8/qgridlayout.html#setRowStretch or take a look at QSpacerItem.

Qt designer: How to add widget to a layout in the designer when the layout appears infinitely thin?

I am using Qt Designer, and I would like to move a couple of top-level widgets into a horizontal layout.
I have dragged a "Horizontal Layout" object into the form. I am now attempting to drag the desired widgets into the layout.
Unfortunately, the new Horizontal Layout widget is infinitely thin:
... and I cannot drag my "Import Progress" label widget or my progress bar widget into the new horizontal layout widget.
Note that when I attempt to drag the desired widgets over the new horizontal layout widget, Qt Designer does not do anything useful for me in terms of expanding the drop region to make the horizontal widget available as a drop target. So I'm stuck.
How do I add widgets to an infinitely-thin layout widget in Qt Designer?
Select the layout, and then drop the widget onto the corresponding selected item in the Object Inspector pane. If you find it tricky to select the layout on the actual form, you can also select it via the Object Inspector pane.
One way (that I usually do as a workaround for not having to show the structure panel) is to select the layout, setting the top or bottom margins to any value (10, whatever) and then dragging the component into the layout. Yeah, that is just for the pure pleasure of dropping the component in the layout, i know, but is a way.
My small trick:
Select layout
Change temporary "layoutTopMargin"
Drop into layout required widgets
Restore layoutTopMargin to default 0

expanding widgets inside a Qtabwidget

Why does the widgets inside a QTabWidget don't resize?
All my widgets resize except for the ones inside the tabs, even the tabs resize, but not the items inside it.
Is this because of the type of layout as I show in the figure?
I can's assign a layout to it. this is before and after maximizing the window.
Why can't you assign a layout to it? You just have to give each tab a layout. Drag your widget into the tab. Select the tab, not the widget, click on one of the layouts in the top row of the designer. Your widget will fill the whole tab and resize nicely.

How to build a Flex FormItem with an image button in the label section?

I want to build a flex FormItem extension that adds a button into the item label section, such that there is both a text label and, to the right of it, a button that uses an image icon:
A form item http://img830.imageshack.us/img830/4411/screenshot20100730at331.png
Basically, I want to create that 'i' icon, such that I can click on it to display a help overlay for the item in question.
Is there an existing component that does this? If not, how do I do it?
Try to use grid, gridrow, and grititem, like the html table. and add the label and the "i" image into a horizontal layout container inside the griditem.
See
http://kennethsutherland.com/2009/05/27/formitem-adding-an-icon/

Resources