Qt World Summit: Submit your Presentation

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.

  • Lifetime Qt Champion


    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):


    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?

  • Lifetime Qt Champion

    Then, you should really have a look at the QGraphicsScene related examples and classes, they will provide you with the building blocks you need

  • Unfortunately, the direct Qt documentation doesn't help me much, as I don't know any C++. I've read the PySide documentation on it, but that doesn't provide any examples on how to code it, so I don't really have any way to figure out how to program it.

  • Lifetime Qt Champion

Log in to reply