Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Questions about software design for a specific problem
isaacEnrique last edited by
I have several questions that are design issues, rather than programming problems itself. However, I understand that good software design is key in creating applications, so I'm asking my doubts.
I am creating a software tool in which the GUI is a window (more exactly a QWidget) showing several elements, including an image and some buttons. I'm using QtDesigner.
I want buttons instead of executing actions when pressed, rather, change the state of the widget. More precisely, there is a button that when you click on should allow the user to select with the mouse a rectangular area of the image. Another button instead should allow the user (when clicked on) to mark points on the image. For these tasks I have thought about using QToolButton with 'checkeable' property set to true ... Is this the best option or are there other ways?
Another question is about the image that the widget should show: initial (and tentatively) I chose to use a QLabel placed within a QScrollArea (to allow zoom), but I don't know if this is the best decision. I also thought I could use a QGraphicsView with QGraphicsScene and function 'QGraphicsScene::addPixmap()' ... What would be an ideal choice for this task?
My last question is the most important (and is why I decided to ask in this forum):
I understand (or at least I think so), that in order to select a region and points of interest in the image must reimplement methods:
'QWidget::mousePressEvent()', 'QWidget::mouseMoveEvent()', 'QWidget::mouseReleaseEvent()' and 'QWidget::paintEvent()'.
What I don't know (or so I'm not sure), is whether these methods reimplemented should be the methods of the subclass of QWidget that I am creating (ie, the window containing the image, buttons, ect) or whether it is better to create a subclass of QLabel (or whatever the widget that has the picture shown) and reimplement (for that class) the methods event handlers and then use that custom widget in my application window. I initial and tentatively, I favor the first option because the way event handlers work depend on the buttons has been checked at all, but I doubt arises because the four functions I should reimplement should only execute I schedule custom actions when the user interact on the image and not on the rest of the application window.
What is the best option in this case? or ... Are there better ways to handle this problem?
Thanks in advance for any help and/or suggestions regarding any of the questions I have raised.
Are you describing a Paint like program ? If so, have a look at Qt's examples and demos, you will find a lot information there
utcenter last edited by
@isaacenrique - you seem to be going ahead of yourself. One could answer all your questions and hardly benefit you, or you could invest more time learning and practicing programming and answer those questions yourself.
Just to give you a quick example of what I mean:
I want buttons instead of executing actions when pressed, rather, change the state of the widget.
Is changing the state of a widget not an action on itself?
On a side note, you could simply draw to a pixmap and then you can put that pixmap wherever you wish, in a label, in a widget, in a graphics view or even in a quick view.
A note of caution: as big as it is, do not expect for Qt to provide everything you can think of out of the box, there are a lot of aspects in which Qt doesn't work as expected or desired, there is no way but to work around that. I've already lost the count of functionality I had to implement on my own after it turns out what Qt does doesn't fit my scenario and cannot be changed to do so easily enough.