How to make a QLabel fill the child QWidget? - c++

I have QWidget, used Lay Out in a Grid, then a QLabel, but there are some spaces between the QWidget and QLabel. How can I make them the same size and not break the layout?
I'm using this from UI editor.

When you select the widget, in the UI editor's property pane you should see the options for the layout that belongs to it (the options have a red background, and they're usually at the bottom of the list). Amongst the options are ones for setting the margin in pixels between widgets in the layout, if you set it to 0 it should solve your problem.

Related

Qt: Force size of QDockWidget

I have a QMainWindow with a center widget and a number of dockable widgets. The size of the various widgets get manipulated by the sliders between the dockables. I would like to fix the center widget's height to it's minimumSize height and not allow it to be made larger by the user. The width should remain relative to the QMainWindow (I only allow top and bottom dockables, so the center widget is stretched to the width of the main window).
The center widget is a QDockWidget, containing a QWidget with a QVBoxLayout (containing more stuff).
I have tried deriving from the QVBoxLayout and overriding maximumSize, but it wasn't respected. Overriding expandingDirections also didn't make any difference.
Any advise on how to achieve this?
Got it, thanks to Johannes Schaub.
I thought the QDockWidget propagates the constraints to its contained widget, which it does not. Setting maximumHeight on the inner Widget does the trick.

How to control background border size of QDialog with QStyleSheet

Using stylesheets, if I set background-color of a QDialog, I don't seem to be able to control the width of the visible colour - the gap between the content and the actual border. For example if I create a QDialog with only a QListWidget on it, in a QGridLayout, I see the background-color appear as a border around the QListWidget. I would like to make this thinner.
How can I reduce this "border"? It looks as thought background-clip would work if QDialog supported the box model.
I am on 4.7 if it makes any difference
That's the layout border. You can reduce it from the design editor by selecting yout QDialog then adjusting the layoutLeftMargin/layoutTopMargin/layoutRightMargin/layoutBottomMargin properties.
You can also set the border width by code by calling setContentMargins on the layout. For example:
ui->gridLayout->setContentsMargins(3,3,3,3); // sets the qdialog border width to 3px.

Qt space around QPushButton in QHBoxLayout

I have a QLabel and a QPushButton added to a QHBoxLayout. The QLabel has its margins set to 0 and the layout has margin and content margins set to 0. The label and button have the same background color and the button has border set to none. However, the button still looks with a brighter color than the label and there is some extra space around the button, so it doesn't look like it's "glued" to the label. I want them to look like one big widget.
In Qt, margins describe the space surrounding the layout. In newer versions of Qt, the margins on the top/bottom/left/right can be set individually through setContentsMargins().
The space between widgets in the same layout is described by the spacing property. The spacing has nothing to do with the margins. Try calling hboxLayout->setSpacing(0); This should work.
Some days ago I have coded a widget with similar behavior. To avoid problems with margins and colors I can recommend to use second QPushButton button instead of QLabel and set both buttons to be flat with btn->setFlat(true);

Make a Toolbar have a grid layout

I want to make a QToolBar have 3 columns of buttons when docked on the left side of the QMainWindow, but have 1 row when docked on the top of the main window. Is this possible?
I have a tried using a QToolBar with a custom layout, but the normal re-size behavior of the QToolBar doesn’t work (doesn’t hide widgets behind an expand button when its too small). The non-working expand button isn’t that big of a deal, but the bigger problem is that the custom layout prevents the main window from being smaller than the toolbar.
I was able to get my desired behavior by putting each row of Tool Buttons in a QHBoxLayout, putting that layout in a empty QWidget, and calling toolBar->addWidget( widget ) for each row. This gives me a grid toolbar when the toolbar is mounted on the left, and single horizontal bar when mounted on the top.

Adding scroll bar to widget containing a layout in QT C++

I am new to QT and I am creating a widget that has a gridlayout. The gridlayout contains a matrix of QLineEdit widgets. The window resizes to fit the layout but when layout is large it goes off screen. When I maximize the screen, the QLineEdit widgets are resized to fit the screen and for large layouts they become extremely small.
I want to be able to resize the window without resizing the QLineEdit widgets and add scroll bars to navigate.
I tried the following with no luck:
Window->resize(QSize(500,500));
QScrollArea *scrollArea = new QScrollArea;
scrollArea->setWidget(Window);
where window is the widget containing the layout. Also, the window closes when after executing "scrollArea->setWidget(Window);" and I dont why.
If someone can help me out I would really appreciate it.
Thank You!
For disabling the vertical resize on the widgets, why don't you just use the setFixedHeight() method on the widgets?
For the menu bar, why don't you take it out of the widget that is scrollable. You can have a layout for the window that contains the menu bar and then the widget that contains everything else (scrollable part). Is that what you are looking for?
I fixed my problem by creating a QMainWindow with the menu bar. Then created a widget which includes the layout, set the Scroll Area to the widget. Finally set the central widget of the main widow to the scroll area.