Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsItem screenshot
QtWS25 Last Chance

QGraphicsItem screenshot

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.7k Views
  • 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
    bunjee
    wrote on last edited by
    #1

    Greetings Qt Dev Network,

    Is it possible to take a screenshot of a specific QGraphicsItem (Not an area of QGraphicsScene but the QGraphicsItem itself) ?

    Has anyone got a straightforward implementation of this ?

    Thanks guys.

    B.A.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      Create a QImage/QPixmap of the item's boundingRect(), create a QPainter on that and then call item->paint()?

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • D Offline
        D Offline
        deimos
        wrote on last edited by
        #3

        I just gone out of this :)
        Here the code I used:
        @
        QImage image(item->boundingRect().size().toSize(), QImage::Format_RGB32);
        image.fill(QColor(0, 0, 0).rgb());
        QPainter painter(&image);
        QStyleOptionGraphicsItem styleOption;
        qobject_cast<QGraphicsObject*>(item)->paint(&painter, &styleOption);
        painter.end();@

        here my "item" is a QDeclarativeitem, but its inerithed by QGraphicsItem, so souldn't be any problem I think.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bunjee
          wrote on last edited by
          #4

          Thanks guys !

          It looks easier than I thought. I wonder if item transformations can screw up the painting.

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

            @deimos: your mediadownloader is a nice piece of software !

            Are you playing the videos natively using FFMPEG and QPixmap(s) ?

            B.A.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              deimos
              wrote on last edited by
              #6

              bq. I wonder if item transformations can screw up the painting.

              whit that code the image grabbed will be the item without transformations. But if you inscribe your item into another, you can then grab the outer one with the inner rotated :)

              bq. @deimos: your mediadownloader is a nice piece of software !
              Are you playing the videos natively using FFMPEG and QPixmap(s) ?

              thanks a lot. Compliments are always welcome and I didn't received a lot even if it is been downloaded a lot :)
              Video are played with phonon (I am rewriting it using QtMultimediaKit without phonon) and since youtube needs cookies and with phonon you have not direct access to network (you can't set QNetworkRequest) I have subclassed QIODevice to threat streaming videos as a local file. They can be played also with mplayer. FFMPEG is used only to convert them.

              sorry to all for this OT

              @bunjee: if you want to find me I am in #qt, #meego channels at freenode irc :)

              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