Widget overlapping other widget in QGridLayout is visible, but unresponsive
-
I have a somewhat special setup that (mis-)uses a QGridLayout to stack one widget over another. Something like this:
QWidget *p_sidebar = new QWidget; // Orange widget p_sidebar->setFixedWidth(50); QWidget *p_work_area = new QWidget; // Blue widget QGridLayout *p_layout = new QGridLayout; p_layout ->addWidget(p_work_area, 0, 0); p_layout ->addWidget(p_sidebar, 0, 0);
The idea is to have p_work_area span across the window and p_sidebar sitting above it on the left side. Then I can expand p_sidebar's width to show some settings on it while it overlaps p_work_area instead of pushing it to the side.The odd thing is that this works visually with p_sidebar correctly sitting on top, but it remains unresponsive to clicks. instead they are registered on p_work_area underneath.
I know that I'm abusing the grid layout with this, but it would've been a pretty neat solution to this UI requirement.Can someone explain to me why the widget (that apparently sits on top) does not receive the mouse input in this configuration?
Thanks!
-
You can not have two widgets at the same grid layout possition
-
You can not have two widgets at the same grid layout possition
@Christian-Ehrlicher thats not true, you actually can.
Its not possible from the designer, yes, but you can, like the OP did set multiple QWidgets in one grid layout position.
Or it used to work in Qt5 at least, haven't done/tried it in Qt6
-
@Christian-Ehrlicher thats not true, you actually can.
Its not possible from the designer, yes, but you can, like the OP did set multiple QWidgets in one grid layout position.
Or it used to work in Qt5 at least, haven't done/tried it in Qt6
@J-Hilk said in Widget overlapping other widget in QGridLayout is visible, but unresponsive:
Or it used to work in Qt5 at least, haven't done/tried it in Qt6
You will not get an error message but it will also not work as expected - e.g. only the size hint of the second will be taken into account and others as you can see in the problem description from the OP
-
I have a somewhat special setup that (mis-)uses a QGridLayout to stack one widget over another. Something like this:
QWidget *p_sidebar = new QWidget; // Orange widget p_sidebar->setFixedWidth(50); QWidget *p_work_area = new QWidget; // Blue widget QGridLayout *p_layout = new QGridLayout; p_layout ->addWidget(p_work_area, 0, 0); p_layout ->addWidget(p_sidebar, 0, 0);
The idea is to have p_work_area span across the window and p_sidebar sitting above it on the left side. Then I can expand p_sidebar's width to show some settings on it while it overlaps p_work_area instead of pushing it to the side.The odd thing is that this works visually with p_sidebar correctly sitting on top, but it remains unresponsive to clicks. instead they are registered on p_work_area underneath.
I know that I'm abusing the grid layout with this, but it would've been a pretty neat solution to this UI requirement.Can someone explain to me why the widget (that apparently sits on top) does not receive the mouse input in this configuration?
Thanks!
@Christian-Ehrlicher interesting, never dove to deep into the situation. The size hint was always all I needed from this hack :D
@qwasder85 have you considered fusing
p_work_areaand p_sidebar into one custom QWidget ? should solve your issues -
@J-Hilk said in Widget overlapping other widget in QGridLayout is visible, but unresponsive:
Or it used to work in Qt5 at least, haven't done/tried it in Qt6
You will not get an error message but it will also not work as expected - e.g. only the size hint of the second will be taken into account and others as you can see in the problem description from the OP
@Christian-Ehrlicher The result is a mixed situation. The widgets are resizing/moving correctly within the layout. But as I mentioned, they appear to not work correctly otherwise.
@J-Hilk I certainly can create a completely custom widget for this case. But it would be too much effort for me right now. If this worked the way I tried, it would have solved my issues really elegantly.
Thank you, guys.
-
@qwasder85 I don't know Qt's event forwarding code by heart, but my guess is that it uses layout as a shortcut to find the right widget and it gets confused by this.
Honestly, unless it's documented somewhere, this looks more like a bug than a feature. I wouldn't rely on it even if it worked.
Can't you just make
p_sidebara child ofp_work_areaif you want to cover it? Sounds like a more sensible approach structure wise.