Qt Draw/drag and drop
-
I have a question about Qt development gui options. I want to create a garden bed layout program, so I want to create a "draw" interface, where the user can "draw" on a grid to lay out the garden beds (and right click on the squares to "plant seeds"). Is this possible in Qt?
This link is http://i59.tinypic.com/eg2wkh.png the start of my gui prototype for the main window. I drew the graph manually right now, and if I need to I can do that again.
-
Hi,
You have several way to do it, e.g. QML, QGraphicsView. You should have a look at the demos & examples from the documentation to see which solution provides what's you want.
Hope it helps
-
I'm using Pyside to create the application (I'm very new to python and QT), and have the following code to create the background "grid":
@class mainWindow(QtGui.QMainWindow, Ui_mainWindow):
def init(self, parent=None):
QtGui.QMainWindow.init(self, parent)
self.setupUi(self) #draw all the UI elements
#drawing the SFG grid
scene = QtGui.QGraphicsScene()
for x in range (-500, 500, 60):
for y in range (-300, 300, 60):
scene.addRect(QtCore.QRectF(x,y,60,60))self.gridView.setScene(scene)@
Now I would like to draw a bold line around a set number of boxes (defining bed sizes) and then be able to click on individual boxes and add pictures to each box (showing plants).
This works, but I can't create a mouse event in the same class apparently, but I can't seem to create a scene class that works:
@class createScene(QtGui.QGraphicsScene):
def init(self, parent=None):
QtGui.QGraphicsScene.init(self, parent)
gridScene = QtGui.QGraphicsScene()
for x in range (-500, 500, 60):
for y in range (-300, 300, 60):
gridScene.addRect(QtCore.QRectF(x,y,60,60)) @How can I capture mouse events in the scene, and how do I select the boxes I created?
-
Then, you should really have a look at the QGraphicsScene related examples and classes, they will provide you with the building blocks you need
-
-
Have a look "here":https://qt.gitorious.org/pyside/pyside-examples/source/060dca8e4b82f301dfb33a7182767eaf8ad3d024:examples there's the example you've been searching :)