Results 1 to 4 of 4

Thread: QGraphicsScene with 4 QImages

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene with 4 QImages

    You say you are in a QThread. Probably calculating those images you want to be displayed. That is perfectly fine.

    Now you will not be able to display them directly from that thread, whatever method you choose. The actual painting has to be done from the gui thread.

    But you can quite easily create a descendant of QObject and QGraphicsItem that has a slot where you update a pixmap-member that you draw in the paintEvent. To prevent simultaneous painting and write-access protect the pixmap with a mutex. Lock it when updating and when painting.

    Instead of manually protecting the pixmap you could also rely on Qt's queued connections, which will be the default connection type for objects living in different threads anyway! Then the update signal will be executed in the context of the gui-thread and you can set the pixmap of a QGraphicsPixmapItem directly. Keep in mind that the QThread object itself is not 'living' in the thread. But with the 'new' way of using QThreads, namely not subclassing QThread but moving a worker class to a QThread-instance, that should not be a problem.

    Whenever your thread has a pixmap ready it just signals your item the update.

    You add 4 of these items to your scene and set their positions with setPos.

    HIH

    Joh
    Last edited by JohannesMunk; 1st April 2011 at 11:28. Reason: updated contents

Similar Threads

  1. Replies: 5
    Last Post: 22nd October 2010, 09:29
  2. Bug in QGraphicsScene?
    By tbcpp in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2009, 14:23
  3. in QGraphicsScene matrix of other QGraphicsScene
    By Noxxik in forum Qt Programming
    Replies: 5
    Last Post: 15th February 2009, 17:27
  4. Help on QGraphicsScene
    By Sandip in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2008, 14:20
  5. Question about QImages
    By SkripT in forum Qt Programming
    Replies: 14
    Last Post: 27th January 2006, 11:45

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.