Designer for restaurant floor plan maker
-
I'm writing a floor plan maker for a restaurant, I'm looking for advice on whether I'm going in the right direction or if there are better/more practical ways.
Currently, I'm heavily relying on
mousePressEvent()
to store the current position of the mouse,mouseReleaseEvent()
to detect if it was a drag or a click, and I'm painting theQRect
inpaintEvent()
.So, in the end, I'm only painting dots (for the grid) and rectangles inside a
QWidget
, if I want to allow the user to drag a table, then I must detect if I'm on a rectangle or not inmousePressEvent()
. It seems straightforward to me but I wonder if I could have implemented that differently than usingpaintEvent()
? -
Hi
For such App, I would go with
https://doc.qt.io/qt-5/graphicsview.htmlas then you get selection / dragging / zooming / panning / groups all for free. (or VERY little code)
You can even use QPainter to paint the custom items and still have all the rest.
Try out this example and see
https://doc.qt.io/qt-5/qtwidgets-graphicsview-diagramscene-example.html -
Hi
For such App, I would go with
https://doc.qt.io/qt-5/graphicsview.htmlas then you get selection / dragging / zooming / panning / groups all for free. (or VERY little code)
You can even use QPainter to paint the custom items and still have all the rest.
Try out this example and see
https://doc.qt.io/qt-5/qtwidgets-graphicsview-diagramscene-example.html@mrjj Very nice suggestion thank you! I'm experimenting since yesterday and it's nice.
I'm currently "drawing" custom
QGraphicsItem
as invisible squares with a dot on the center, and the dot is supposed to be a snapping grid, corners of a table can only be drawn on a dot. The inside of the item is supposed to detect where the mouse is. So these items are only used to detect hovering.Then, on drag from a "dot", I'm supposed to draw a
QGraphicsRectItem
, itself movable, resizable, etc… Is it the right way to use the Graphics View Framework?I'm still open to eventual other suggestions.
-
@mrjj Very nice suggestion thank you! I'm experimenting since yesterday and it's nice.
I'm currently "drawing" custom
QGraphicsItem
as invisible squares with a dot on the center, and the dot is supposed to be a snapping grid, corners of a table can only be drawn on a dot. The inside of the item is supposed to detect where the mouse is. So these items are only used to detect hovering.Then, on drag from a "dot", I'm supposed to draw a
QGraphicsRectItem
, itself movable, resizable, etc… Is it the right way to use the Graphics View Framework?I'm still open to eventual other suggestions.
@Max13
Good to hear. Yes for a floor plan app it should give a lot of nice features.Hmm. Im not 100% sure what you mean with that dot.
I assume you want something like
https://www.walletfox.com/course/qgraphicsitemsnaptogrid.phpwhere it uses drawBackground to draw a grid and then the Items itemChange that can catch the movement and adjust the placement to hit the grid.
-
@Max13
Good to hear. Yes for a floor plan app it should give a lot of nice features.Hmm. Im not 100% sure what you mean with that dot.
I assume you want something like
https://www.walletfox.com/course/qgraphicsitemsnaptogrid.phpwhere it uses drawBackground to draw a grid and then the Items itemChange that can catch the movement and adjust the placement to hit the grid.
@mrjj Here is what I have done with
paintEvent()
,mouseMoveEvent()
,mousePressEvent()
andmouseReleaseEvent()
, that's what I mean by "dot": https://imgur.com/a/cF5EeTWNow, using
QGraphicsItem
, I have subclassed it toDot
which has a square asDot::boudingRect()
and is painted as a 2px ellipse (a dot).Should I use my "dot" as a grid, and detect hover, press, and drags when the user is drawing a table, then constrain the user to this "grid" of
Dot
then addQGraphicsRectItem
as the tables, OR maybe stick topaintEvent()
to draw (exactly as I did on the video) and only use the Graphic View Framework for the tables ?