Results 1 to 9 of 9

Thread: Custom QGraphicsItem - Adding a QListWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Custom QGraphicsItem - Adding a QListWidget

    So what exactly is the problem?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Sep 2012
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default Re: Custom QGraphicsItem - Adding a QListWidget

    It's easier if I draw a picture to explain what's happening.

    What I want is something like this:

    Attachment 8216

    with the QListWidget inside the lower of the two inner QGraphicsRectItems.

    What I get is the basic graphics classes drawing on the View OK, but the QListWidget is in a window of its own, in a different location, not attached to the inner rectangle. Something like this:

    GraphicsItemWithoutList.JPG

    Obviously, I've done something wrong, but I'm not exactly sure what. Hope this helps to clarify my problem.

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

    Default Re: Custom QGraphicsItem - Adding a QListWidget

    You are not adding the list widget to the scene anywhere. And you certainly cannot pass a QGraphicsRectItem as a parent to QListWidget since the former is not a widget at all (dynamic_cast will return 0 here).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Sep 2012
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default Re: Custom QGraphicsItem - Adding a QListWidget

    The code snippets I've provided don't show the addition of the Custom CommunityDisplay Class to the scene. That is done elsewhere, and pointers to the created CommunityDisplay class are added to the scene using QGraphicsScene::addItem.

    I'd assumed that the QListWidget internal to the custom class would have been added to the scene with the scene.add(customclass) call I'm doing. Is this not the case?

    I'd also suspected that I couldn't force the QGraphicsRectItem to be a parent to the QListWidget, so thanks for confirming that - I'll remove that. I would also guess that the main reason that the QListWidget is being displayed in its own window is that the mapToParent method won't work when the parent was invalid (0, as you pointed out in the previous reply).

    I'm still a little stumped as to how to get the List to display within the custom class on the scene. Any further thoughts?

    EDIT: Actually, you're absolutely right about not having added the QListWidget to the scene - all the other graphics items within the custom class have the parent scene passed in the constructor when they're newed. However, that still doesn't fix the problem, as I'm not sure there's a valid way of adding the widget to the scene, as scene.addItem requires a QGraphicsItem pointer, and I won't be able to dynamic_cast it to QGraphicsItem * from QWidget * in the same way as I couldn't dynamically cast in the opposite direction...
    So, I guess the question is: Is it actually possible to add a QListWidget (or QListView) to a QGraphicsScene?
    Last edited by El Bazza; 12th September 2012 at 16:12.

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

    Default Re: Custom QGraphicsItem - Adding a QListWidget

    Quote Originally Posted by El Bazza View Post
    The code snippets I've provided don't show the addition of the Custom CommunityDisplay Class to the scene.
    You don't understand. You are not adding the list widget object to the scene. It doesn't have a parent (as I explained in the previous post) and thus is not tied to the scene in any way and shows up as a separate window.

    Have a look at QGraphicsProxyWidget class to see how to add a widget to a scene. However be prepared for major slowdowns if you intend to animate the item. Widgets are not supposed to be placed on graphics scenes.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    El Bazza (12th September 2012)

  7. #6
    Join Date
    Sep 2012
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default Re: Custom QGraphicsItem - Adding a QListWidget

    Thanks wysota, I realised that after I'd posted the reply, hence the edit

    Thanks also for the pointer to QGraphicsProxyWidget, I think I see how it should all work now. The QListWidget remains in the custom class, along with a pointer to a QGraphicsProxyWidget, which is used to display the information held within the QListWidget
    EDIT: I've just checked the basics of the principle, and I now have a List Widget inside my Graphics Scene. Thanks once again, wysota
    Last edited by El Bazza; 12th September 2012 at 17:30.

Similar Threads

  1. (PyQt4) QtGui QListWidget adding new item problem
    By mshemuni in forum Qt Programming
    Replies: 0
    Last Post: 4th September 2012, 05:05
  2. QListWidget, help adding new items.
    By JeremyRussell in forum Newbie
    Replies: 4
    Last Post: 7th April 2011, 00:54
  3. Replies: 1
    Last Post: 22nd February 2010, 11:53
  4. adding QGraphicsItem to multiple scenes
    By forrestfsu in forum Qt Programming
    Replies: 7
    Last Post: 6th November 2006, 15:25
  5. [Qt4]: Adding centered items in QListWidget
    By Jojo in forum Qt Programming
    Replies: 4
    Last Post: 16th March 2006, 21:04

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.