Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How can I do pixel image drawing with Python and QML?
Forum Updated to NodeBB v4.3 + New Features

How can I do pixel image drawing with Python and QML?

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 5.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CaCO3
    wrote on 28 Aug 2011, 10:59 last edited by
    #1

    I am sorry if I do a double post with the MeeGo forum, but up to now I haven't got a helpful answer. So I hope I can get some more help here.

    For Maemo 5 I wrote some applications which do pixel drawing with a QPainter.
    I am now wondering how I could port this to QML.

    I searched the web quite a while, but couldnt find any examples how to paint from Python on a QML page.

    On PyQt I did it like this:
    @
    class MyCanvas(QtGui.QWidget):
    def init(self, parent=None):
    QtGui.QWidget.init(self, xxx)
    self.setGeometry(10, 180, 781, 241)

    def paintEvent(self, event):
    paint = QtGui.QPainter()
    paint.begin(self)
    paint.setPen(QtGui.QColor("gray"))
    paint.setBrush(QtGui.QColor("black"))
    paint.drawRect(0,0,780,240)
    paint.end()

    canvas = MyCanvas()
    canvas.show()@

    This then draw directly on my QWidget.

    So my question is, how would I be able to do something like this with QML?
    I know there are some C++ examples, but I do not understand how to adapt them to Python :(
    Edit/Delete Message

    1 Reply Last reply
    0
    • R Offline
      R Offline
      renato.filho
      wrote on 29 Aug 2011, 14:46 last edited by
      #2

      Hi take a look on this example write using PySide: https://qt.gitorious.org/pyside/pyside-examples/blobs/HEAD/examples/declarative/extending/chapter1-basics/basics.py

      I know this is possible using PySide I do not know if is possible to do thin on PyQt.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        CaCO3
        wrote on 29 Aug 2011, 21:36 last edited by
        #3

        Thank you very much!
        This was exactly what I was looking for.

        I am using PySide, so I don't bother PyQt. How ever they are mostly compatible, so it might work there as well.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          CaCO3
          wrote on 30 Aug 2011, 13:42 last edited by
          #4

          I got it working quite well, how ever now I am facing a new problem:
          In python, I have a timer which should redraw my graph every 1 seconds. How ever, how do I force the update?
          Before I could do it in this way:
          @canvas.update()@
          update() then would somehow call the paintEvent function in the canvas object.

          But now I register the QML object with
          @qmlRegisterType(Graph, 'myAngleGraph', 1, 0, 'AngleGraph')@
          so there is no object I could call within Python.

          I guess there would also be a way of having a timer in QML which reloads the graph, but I would prefer to do it from Python so I only redraw it when necessary.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            CaCO3
            wrote on 2 Sept 2011, 22:05 last edited by
            #5

            I found now a solution. It might not be the nicest one, but it works.

            In python, I call a function in QML, and from there I move the graph around, just one pixel right and left again. this then forces a redraw.

            For more infos about it, have a look here: http://forum.meego.com/showthread.php?t=4412

            1 Reply Last reply
            0

            1/5

            28 Aug 2011, 10:59

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved