Results 1 to 4 of 4

Thread: Casting QGraphicsItem child from QGraphicsItem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2006
    Posts
    788
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    49
    Thanked 48 Times in 46 Posts

    Default Re: Casting QGraphicsItem child from QGraphicsItem

    I solved on other Type to makeit readable ....


    Qt Code:
    1. enum { Layer = 1 };
    2. int type() const {return Layer;}
    3.  
    4.  
    5. template <class T> inline T layer_cast(QGraphicsItem *item)
    6. {
    7. return int(static_cast<T>(0)->Layer) == int(AbsoluteLayer::Layer)
    8. || (item && int(static_cast<T>(0)->Type) == item->type()) ? static_cast<T>(item) : 0;
    9. }
    10.  
    11. template <class T> inline T layer_cast(const QGraphicsItem *item)
    12. {
    13. return int(static_cast<T>(0)->Layer) == int(AbsoluteLayer::Layer)
    14. || (item && int(static_cast<T>(0)->Type) == item->type()) ? static_cast<T>(item) : 0;
    15. }
    16.  
    17.  
    18.  
    19. AbsText::AbsText()
    20. : device(0)
    21. {
    22.  
    23. }
    24. /* only one connect */
    25. LayerText *AbsText::txtControl() const
    26. {
    27. if (!device) {
    28. AbsoluteLayer *that = layer_cast<AbsoluteLayer *>(q);
    29. device = new LayerText(); /* text-api all event */
    30. connect(device, SIGNAL(q_cursor_newPos() ),q, SLOT(cursor_wake_up()));
    31. connect(device, SIGNAL(q_update(QRect) ),q, SLOT(updatearea(QRect)));
    32. connect(device, SIGNAL(q_visible(QRectF) ),q, SLOT(ensureVisible(QRectF)));
    33. ///////connect(device, SIGNAL(q_update_scene()),q, SLOT(SceneReload()));
    34. }
    35. return device;
    36. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Casting QGraphicsItem child from QGraphicsItem

    You have to change Type to Layer in lines #8 and #14 too.

Similar Threads

  1. Replies: 9
    Last Post: 22nd June 2008, 22:26
  2. Casting QGraphicsItem
    By pherthyl in forum Qt Programming
    Replies: 1
    Last Post: 11th November 2007, 23:56

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.