Adding QWidget without layout to QStackedWidget inlay gap - qt

I have a QStackedWidget that I add multiple QWidget() objects to. Each QWidget has its own layout. For some reason when it adds the QWidget to the QStacked widget, it doesn't add it to say location "0,0"... it seems to always inlay it by 3 or 4 pixels from each edge of the QStackedWidget. See picture for an example...I made the QStackedWidget background black so it is easy to see the gap.
The question is, how can I eliminate this gap and get the QWidget to align perfectly with the QStackedWidget?

If I use the "setContentsMargins(0,0,0,0) on the layout I use for the QWidget the gap goes away.
That is the solution.

Related

Overlay grid onto QFrame

So, I have a QFrame with its layout set as a QGridLayout.
Within this layout I have tiles in rows of 16 which represent something of a palette.
I want this grid of tiles to be separated by lines, like a grid should be. I can do this easily with the tiles' paintEvents.
However, the obvious problem is that between the tiles, the lines are doubled up. When I scale this up for other applications, the difference becomes even more noticeable.
So, is there a way to create a gridline overlay for my QFrame? I have considered converting the whole thing to a view/scene solution, and using drawForeground, however this seems like a completely inappropriate use of the paradigm.
Thanks for any assistance!
Put the QFrame into a QGridLayout, then put a custom QWidget with transparent background and paintEvent that paints the grid on top of it (same QGridLayout position).
Or since you already have a QGridLayout, just put the custom QWidget in that, above the tiles, filling the entire grid.
A side note, are you sure you want QFrame there, or if just QWidget would do? Just saying, because with QFrame you get that 1990's look into your UI... If you do want that then go ahead, just saying.

Make QListWidget fill QFormLayout

I am using QT4 Designer have a layout that looks basically like this:
QWidget
QVBoxLayout
QFormLayout
QLineEdit
QListWidget
QPushButton
Each control is on a separate line.
I did the layout assignment trick to get everything to fit to the parent, and if I reduce the height the QListWidget shrinks as hoped, but if I increase the height the QWidget.geometry.Height never exceeds 192. The Vertical Policy is set to Expanding and the maximumSize.Height is 16777215, but no other policy seems to allow the QListWidget to grow. Width grows correctly, however.
What setting am I missing? Should I instead anchor the QPushButton to the bottom of the QFormLayout, and if so, how?
Well, I found my own answer - I selected the QFormLayout, right-clicked, and chose Lay out/Lay Out in a Grid and everything snapped into place! So, the new, working hierarchy is:
QWidget
QVBoxLayout
QGridLayout <<-- Changed from QFormLayout
QLineEdit
QListWidget
QPushButton

Scrollable DockWidgetArea in QMainWindow

Is there any possibility to make DockWidgetArea in QMainWindow scrollable? I have many instances of QDockWidget that cannot fit into the area without scrolling. Basically, I need to have two “side bars”, one on the left, second on the right of the main window. These side bars has to be floatable on the whole and so be able to be moved to secondary monitor.
I have tried adding three instances of QMainWindow into the horizontal layout, used the middle one for showing the main application content and the rest as a dock areas – their central widget has zero size.
It works except that I am not able to add a scrollbar into these "dock areas". More precisely, I can add a QScrollBar as a central widget of these QMainWindows, but it breaks docking ability and that is all.
In Qt 4 there was QDockArea widget, but in Qt 5 one has only a minimal control of the dock areas behavior.
Is there any solution for that?

Drawing inside a QFrame: coordinate system

I would like to draw inside a Qt QFrame, however the QFrame will have a border. As far as I understand, the paintEvent receives a QPainter which is associated to the whole frameRect, so I will have to offset my paint operations of the border. Is this correct? Is there a way of getting a QPainter already associated to the inner part of the widget, without the (variable in size) border?
you have to consider the contentsRect contentsRect()-> Returns the area inside the widget's margins.using the return value rect of contensRect() you can restrict to draw anything inside the rect.
One way to do this would be to embed a QWidget inside the QFrame, place it in a simple QVBoxLayout layout or QStackedLayout layout with no margins and paint the QWidget instead. You'll probably get better performance if you simply offset your painting, though.

How to prevent QTableWidget from occupying the whole window in a QHBoxLayout?

In my Qt program, I programmatically generate a modal QDialog. I want to show two widgets in this dialog window: A custom widget showing a camera output and a QTableWidget, showing the pixel coordinates of the corners found in the camera image. I generate a QHBoxLayout and add my custom widget and the QTableWidget into it. Then I set this QHBoxLayout as the Layout of the QDialog window. What I want to achieve is to share the available space in the QDialog's window area equally between my custom QWidget and the QTableWidget, horizontally, by using a QHBoxLayout. But I always end up with QTableWidget occupying the whole QDialog area, by overlapping my custom widget. How can I instruct these two widgets to exactly share the QDialog area?? Note that I first add my custom widget and then the QTableWidget into the QHBoxLayout.
Make sure on your custom widget you've specified a minimumSizeHint and a sizeHint, this instructs the QLayout manager that the widget requires a specific space. To have them split equally you'll be best off detecting the size of the QDialog and then specifying the width for both by removing the boundary sizes (spacing between widgets + space to QDialog edge) and dividing it up.

Resources