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. Drawing to QtQuick Canvas from cpp
Forum Updated to NodeBB v4.3 + New Features

Drawing to QtQuick Canvas from cpp

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.8k 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.
  • B Offline
    B Offline
    bitskull
    wrote on last edited by
    #1

    Hi, I created UI for my app using QtQuick.
    I need canvas for my gfx output so I placed QtQuick Canvas object to my QML file.
    I was able to connect QtQuick Canvas.paint signal to my cpp CCanvas.onPaint slot.
    Now I do not know how to get QtQuick Context2d equivalent in cpp.
    I found QPainter in documentation and it looks good.
    Can I get QPainter for QtQuick Canvas?
    I need context where I can draw lines, polygons, etc. (something as cairo context).

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jens
      wrote on last edited by
      #2

      The canvas is specifically designed for convenient use within javascript. If you are in C++ you should instead use QQuickPaintedItem which specifically provides the same functionality through QPainter instead.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bitskull
        wrote on last edited by
        #3

        Thank you!
        I derived my class from QQuickPaintedItem and it works.
        However I found this statement in documentation:

        bq. QQuickPaintedItem is meant to make it easier to port old code that is using the QPainter API to the QML Scene Graph API and it should be used only for that purpose.bq.

        Does it mean I should use completely different approach for new application?

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jens
          wrote on last edited by
          #4

          Not at all, you can safely use it. We have in fact removed that specific quote from the documentation in 5.2 as it is essentially incorrect. QQuickPainted item is the appropriate way to use QPainter code in Qt Quick 2 when you need it. The only warning is that QPainter code will generally be less performant than using pure Qt Quick items as it is not hardware accelerated. But a QQuickPanted item in C++ is probably a little bit faster than using Canvas.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bitskull
            wrote on last edited by
            #5

            thanks for the clarification

            1 Reply Last reply
            0

            • Login

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