Results 1 to 4 of 4

Thread: QCanvasItem as QWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2008
    Posts
    2
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QCanvasItem as QWidget

    Hi All,
    Is it possible to to have a custom QCanvasItem which can act as a widget as well?
    For e.g. it can generate signals like 'clicked'.

    ~ A newbie

  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: QCanvasItem as QWidget

    With a little work you can make QCanvasItem emit clicked() signal. First you have to make QCanvasView detect mouse clicks. The rest is easy.

  3. #3
    Join Date
    Jul 2008
    Posts
    2
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QCanvasItem as QWidget

    Thanks Jacek.
    As I could understand from your response, I am capturing mouse clicks on the QCanvasItem. This I am using to generate a new QCanvas/view which shows details (some more diagrams) for the object represented by QCanvasItem.
    Is this a right appoach?

  4. #4
    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: QCanvasItem as QWidget

    Quote Originally Posted by sanjay View Post
    As I could understand from your response, I am capturing mouse clicks on the QCanvasItem.
    No, QCanvasItem can't capture mouse clicks --- only QCanvasView can do that. You just have to forward the information about mouse click from the canvas view to the canvas or canvas item.

    In order to allow canvas items to emit signals you have to turn them into QObjects. If you have a lot of such items, it might not be the best approach. So instead you can consider emitting the signal from the canvas or canvas view.

  5. The following user says thank you to jacek for this useful post:

    sanjay (11th July 2008)

Similar Threads

  1. Display a QWidget using multi-screen
    By tarod in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 14:02
  2. Error in put one QWidget in another QWidget
    By xjtu in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2008, 16:05
  3. Replies: 4
    Last Post: 24th April 2007, 13:18
  4. When is the best time to delete a QCanvasItem
    By irudkin in forum Qt Programming
    Replies: 12
    Last Post: 8th March 2007, 21:28
  5. Replies: 3
    Last Post: 8th March 2007, 14:54

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.