Results 1 to 6 of 6

Thread: View, Scene, Item and thread??

  1. #1
    Join Date
    Jun 2007
    Posts
    15
    Thanks
    2

    Default View, Scene, Item and thread??

    Hi all,
    I create a small application with QGraphicsView, QGraphicsScene, QGraphicsRectItem and thread: a view display many icons( subclass QGraphicsRectItem and QThread) in left, right, and one in center of view. When user click on a left item, the central one will move to right and the clicked one will move from left to center( animation). Each object icon subclass from QGraphicsRectItem and QThread:

    Qt Code:
    1. class RectIcon: public QThread, QGraphicsRectItem
    2. {
    3. RectIcon(QString imagePath); //contain the path of image to load.
    4.  
    5. void paint(...); // draw the item
    6. protected:
    7. void run();
    8.  
    9.  
    10. private:
    11. void toLeft();//move the image from right or center to left
    12. void toRight(); // change the position by rotate and transform.
    13. void leftToCenter();
    14. void rightToCenter();
    15.  
    16. };
    17.  
    18. RectIcon::run() // this will be called when user click on one item, this item will be move to center and the central one will to right or left.
    19.  
    20. {
    21. while( _canRun)
    22. {
    23. toLeft();
    24. toRight();
    25. leftToCenter();
    26. rightToCenter();
    27. usleep( 19000);
    28. }
    29. }
    To copy to clipboard, switch view to plain text mode 

    When user click on one item( left or right), the view will specify the clicked item and call start() function, in run() function, we will translate, rotate and change the position of this item. in a short time( after running the application about 3-4 minutes), it's right- the clicked item can move to the center. after that, although the item change the position but the view is not refresh to see animation. to see the latest images, we must resize the view window.

    Could you tell me why and how to resolve this problem( view can refresh)?
    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: View, Scene, Item and thread??

    First of all you shouldn't mix GUI and threads or Bad Things(tm) will happen.

    See QGraphicsItemAnimation, QTimeLine and QTimer.

  3. #3
    Join Date
    Jun 2007
    Posts
    15
    Thanks
    2

    Default Re: View, Scene, Item and thread??

    thanks, first, we use QTimeLine to animate all items but it's not flexible, smooth and so slow with many icons( about 100 icons). So, we converted it to thread. We use QgraphicsRectItem to get the border of rect item, monitor other things( right-click to open maximize, minimize the correspoding window, change the mode of view( quick view, cascade, browser view, tile view...). I think QGraphicsRectItem is more suitable.

    Any other idea?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: View, Scene, Item and thread??

    You don't need 100 timelines nor 100 threads. Have a single animation controller that will periodically (QTimer) move all the animating items based on their state.

  5. #5
    Join Date
    Jun 2007
    Posts
    15
    Thanks
    2

    Default Re: View, Scene, Item and thread??

    yes, that's right. But, we add another feature into the application: when the mouse is over one item( hover), that item icon will jump( change the y-axis position) while other items are moving. If we use timeline with jump feature, it is very slow with 100 item icons.
    Please give me a solution with thread.
    thanks!

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: View, Scene, Item and thread??

    Why do you think threads will help you?

Similar Threads

  1. Inserting Item to a QTreeWidget from Thread?
    By vishal.chauhan in forum Qt Programming
    Replies: 3
    Last Post: 23rd June 2007, 12:23

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.