Overlapping widgets
-
I'm a new user of Qt, and I have a question about overlapping widgets. I've been working on a calculator project: https://gitlab.com/stevenfalco/hp67-emulator
I've gotten it working, but now I want to be able to scale the mainwindow. I have a number of overlapping widgets:
There is a QLabel covering the whole centralwidget - it shows the background image of the calculator.
There are also three QGridLayouts for the various QPushbuttons, but those layouts are not in a vertical stack, because I wanted to fine-tune the placement.
I also have an overlap of a QPushbutton (called "card") and a QGraphicsView (called "card_view"). The "card" pushbutton is on top, and is transparent, so the user just sees the "card_view" underneath it.
Similarly, I have some overlapped buttons and graphics views for the slide switches at the top of the calculator.
I'd like to restructure this to be more in line with a proper layout, but I'm not sure how to go about it.
I could also consider getting rid of all the buttons and just handle mouse events myself, but that feels like a bad design, and I'd still need to overlap the various graphics views with the underlying background image.
Please let me know what would be a suitable design, as I am very new to Qt, and to C++ also.
-
@SteveFalco
I think what you are saying is that you have a background image of the calculator on which everything has to be positioned. You then overlap widgets and place transparent buttons, in layouts, in order to interact with the image.I wonder whether you would be happier with a
QGraphicsScene
/View
, perhaps with the image set as the background, on which you detect click areas and/or place graphics objects? Widgets and layouts are great for abstract positioning, resizing, scaling, but not for ensuring items are at specified positions. -
@SteveFalco said in Overlapping widgets:
There are also three QGridLayouts for the various QPushbuttons
A quick QoL improvement/reducing LoC:
I checked the repo out nd noticed that you have over 130 lines of code just to connect all buttons to the same two signals (calculatorButtonClicked
and-Released
).
It can save at least 100 lines if you group all buttons in one container and connect each button to these two signals while iterating.
You could also work withQButtonGroup
or useQSignalMapper
. -
@SteveFalco said in Overlapping widgets:
I haven't learned about iterators yet. :-)
I dont say you have to use a "real" iterator.
There is this mysterious thing calledfor
loop :-) -