Results 1 to 19 of 19

Thread: Binding data to a a QGraphicsItem (or something like that)

  1. #1
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Binding data to a a QGraphicsItem (or something like that)

    Ok, I have a QGraphicsScene full of QGraphicItem's.
    What I hope to achieve is to somehow "assign" a QString to each of the QGraphicItem's when they are created.
    Ex:
    Qt Code:
    1. create QGraphicItem
    2. assign QString "this data" to it
    To copy to clipboard, switch view to plain text mode 

    By doing that, when a user clicks on the respective QGraphicItem, I can call a function passing as an argument the previously assigned QString.

    Qt Code:
    1. when I click on QGraphicItem
    2. call useData(assigned QString)
    To copy to clipboard, switch view to plain text mode 

    Makes sense? Hope so.

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Binding data to a a QGraphicsItem (or something like that)

    and its working aa ..? urs seems to be useful for me ..
    becuase previouly i am doing signal mapping and emitting th signal ..
    "Behind every great fortune lies a crime" - Balzac

  3. #3
    Join Date
    Aug 2006
    Location
    istanbul, turkey
    Posts
    42
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Binding data to a a QGraphicsItem (or something like that)

    why don't you use inheritance?

  4. #4
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Binding data to a a QGraphicsItem (or something like that)

    How would I use innheritance? One thing I miss very much from Actionscript 3 , Is that doing this is as simple as:

    Qt Code:
    1. var rHolder:Array = new Array();
    2. for(var i:int=0;i<10;i++){
    3. rHolder.push( new Object() );
    4. rHolder[i].data= "my data goes here";
    5. rHolder[i].info = "my info";
    6. rHolder[i].movieClip = new card(); // card here being the movieClip class // new on AS3
    7. }
    To copy to clipboard, switch view to plain text mode 

    Is there a way I can simulate that?
    Another option is maybe to create a array with the info in order that the GraphicsItem's are being made:

    Qt Code:
    1. new array;
    2. for(...)
    3. array[i] = " QGraphicsItem just created data";
    To copy to clipboard, switch view to plain text mode 
    Then:
    Qt Code:
    1. When QGraphicsItem is double clicked{
    2. int num = this items number in order of creation;
    3. myFunction( array[num]);
    4. }
    To copy to clipboard, switch view to plain text mode 

    I dont know...

  5. #5
    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: Binding data to a a QGraphicsItem (or something like that)

    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. #6
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Binding data to a a QGraphicsItem (or something like that)

    Oh... So simple. Does that take a lot of data, or is it just for small numbers and\or strings? For me its just what I need.

    If I want to retrive that data when the item is clicked, how is that done?I've tried this:
    Qt Code:
    1. bool DropArea::eventFilter(QObject *object, QEvent *event){
    2.  
    3.  
    4.  
    5. if (event->type() == QEvent::GraphicsSceneMouseDoubleClick)
    6. {
    7. dblClick(object);
    8. return true;
    9. }
    10. return false;
    11. }
    12.  
    13. void DropArea::dblClick(QObject *item){
    14. // how do I now if this object is a QGraphicsItem?
    15. }
    To copy to clipboard, switch view to plain text mode 
    Thanks for the info.

  7. #7
    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: Binding data to a a QGraphicsItem (or something like that)

    It takes everything that fits into QVariant (which means almost anything).

    Graphics items are not QObjects, you can't do it this way. The proper way is to subclass either the scene or the item and use its proper event handler.
    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.


  8. #8
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Binding data to a a QGraphicsItem (or something like that)

    So I need to subclass void QGraphicsItem::mouseDoubleClickEvent()? Where do I find its "contents"?

  9. #9
    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: Binding data to a a QGraphicsItem (or something like that)

    Quote Originally Posted by been_1990 View Post
    So I need to subclass void QGraphicsItem::mouseDoubleClickEvent()?
    You subclass a class, not a method. You reimplement a method.

    Where do I find its "contents"?
    What contents?
    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.


  10. #10
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Binding data to a a QGraphicsItem (or something like that)

    With "contents" I meant the actuall definition of them. The Docs only have a little explanation on what it does, not the code.
    You subclass a class, not a method. You reimplement a method.
    Oh. Good to know. Then what do I do? Sorry. Thanks for helping.

  11. #11
    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: Binding data to a a QGraphicsItem (or something like that)

    Quote Originally Posted by been_1990 View Post
    With "contents" I meant the actuall definition of them. The Docs only have a little explanation on what it does, not the code.
    The source code is usually not in the docs but in the.... source code. But why would you care? Just call the base class implementation when it's appropriate and the routine will be executed.

    Oh. Good to know. Then what do I do?
    That I do not know. But you surely use improper terms making it harder to understand you.
    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.


  12. #12
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Binding data to a a QGraphicsItem (or something like that)

    Sorry for my lack of C++ jargon knowledge.
    Well you said:
    Graphics items are not QObjects, you can't do it this way. The proper way is to subclass either the scene or the item and use its proper event handler.
    What did you mean? How will I " subclass either the scene or the item and use its proper event handler."?

  13. #13
    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: Binding data to a a QGraphicsItem (or something like that)

    Event handlers are methods that are called when an event occurs. Examples of such methods are QGraphicsItem::mouseMoveEvent() or QGraphicsItem::dragLeaveEvent(). And I'm sure you know what subclassing is.
    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.


  14. #14
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Binding data to a a QGraphicsItem (or something like that)

    Ok, I actually searched Google for subclassing and now I understand...
    When I said:
    Originally Posted by been_1990 View Post
    So I need to subclass void QGraphicsItem::mouseDoubleClickEvent()?
    I actually meant:
    So I need to reimplement void QGraphicsItem::mouseDoubleClickEvent()?
    Thanks for your patience! You are a real help!

  15. #15
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Binding data to a a QGraphicsItem (or something like that)

    Now, how do I get them QGraphicsItem that was clicked? Theres only a QGraphicsSceneMouseEvent * mouseEvent .

  16. #16
    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: Binding data to a a QGraphicsItem (or something like that)

    Please... read some Qt docs... and learn at least the basics of object oriented programming

    QGraphicsItem::mousePressEvent()
    QGraphicsScene::itemAt()
    Last edited by wysota; 12th August 2009 at 21:42.
    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.


  17. #17
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Binding data to a a QGraphicsItem (or something like that)

    Ok, sorry.. hehe

  18. #18
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Binding data to a a QGraphicsItem (or something like that)

    I have a QGraphicsView subclass as my "main function"(the right name is?) I i have reimplemented QGraphicsItem::mouseDoubleClickEvent:

    Qt Code:
    1. void QGraphicsItem::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * event )
    2. {
    3. qDebug() << " mouseDoubleClickEventt in Item" << event->scenePos() << this;
    4. }
    To copy to clipboard, switch view to plain text mode 

    Until here everything works well, :this: returns the item I just clicked. But obviously I can't call any other function from my class DropArea from the above. How can I call a function from another class? Dont even need to give me the answer, just point me where to read on it.

  19. #19
    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: Binding data to a a QGraphicsItem (or something like that)

    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.


Similar Threads

  1. data rate transfer is decreasing in TCP connection
    By navi1084 in forum Qt Programming
    Replies: 3
    Last Post: 19th June 2009, 16:15
  2. Best way to display lots of data fast
    By New2QT in forum Newbie
    Replies: 4
    Last Post: 16th October 2008, 22:46
  3. Replies: 7
    Last Post: 29th August 2008, 10:24
  4. Replies: 4
    Last Post: 19th October 2007, 19:47
  5. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53

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.