Results 1 to 5 of 5

Thread: not drag and drop on a QGraphicsTextItem

  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default not drag and drop on a QGraphicsTextItem

    Hi, I'm trying to solve a problem I was postponing during too much time and now I'm out of ideas.

    I have a subclassed QGraphicsTextItem that only receives the drag and drop event when "mousePressEvent" is not implemented. Everything, everything works perfectly (edit text, change the font...) but drag&drop.

    Qt Code:
    1. #pragma once
    2. #ifndef ITEXTOITEM_H
    3. #define ITEXTOITEM_H
    4.  
    5. #include "Common/TextoItem.h"
    6. #include <QMenu>
    7.  
    8. class CITextoItem : public CTextoItem //CTextoItem inherits from QGraphicsTextItem
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. CITextoItem();
    14. ~CITextoItem();
    15.  
    16. private:
    17. void mousePressEvent(QGraphicsSceneMouseEvent *event);
    18.  
    19. QMenu* m_pMenu;
    20.  
    21. private slots:
    22. void menuClicked(QAction* pAction);
    23. };
    24.  
    25. #endif //ITEXTOITEM
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. void CITextoItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
    2. {//it should work...
    3. QGraphicsItem::mousePressEvent(event);
    4. }
    To copy to clipboard, switch view to plain text mode 


    just in case, the father's class
    Qt Code:
    1. #pragma once
    2. #ifndef TEXTOITEM_H
    3. #define TEXTOITEM_H
    4.  
    5. #include "FormElemItem.h"
    6. #include <QGraphicsTextItem>
    7. #include <QObject>
    8.  
    9. class CTextoItem : public QGraphicsTextItem
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. enum { Type = UserType + 5 };
    15. int type() const
    16. {
    17. // Enable the use of qgraphicsitem_cast with this item.
    18. return Type;
    19. }
    20.  
    21. CTextoItem();
    22. ~CTextoItem();
    23. };
    24.  
    25. #endif //TEXTOITEM_H
    To copy to clipboard, switch view to plain text mode 

    It doesn't mind the code I have inside the mousePressEvent function, drag&drop doesn't work if the function is implemented and it works perfectly if I remove it.

    Do you have any clue? right now, I'm out of ideas.

    thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: not drag and drop on a QGraphicsTextItem

    mousePressEvent() should be public
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    jano_alex_es (19th October 2009)

  4. #3
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: not drag and drop on a QGraphicsTextItem

    it does not work either...

    Should be always public? visual-studio/Qt implements it as private by default. By the way, I can edit the text and it receives events, everything ok but drag&dropping.
    Last edited by jano_alex_es; 19th October 2009 at 09:17.

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: not drag and drop on a QGraphicsTextItem

    Try to make it protected (that's what I use allways...) and
    Qt Code:
    1. void CITextoItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
    2. {
    3. QGraphicsTextItem::mousePressEvent(event);
    4. // or if that don't work
    5. // CTextoItem::mousePressEvent(event);
    6. }
    To copy to clipboard, switch view to plain text mode 

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

    jano_alex_es (19th October 2009)

  7. #5
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: not drag and drop on a QGraphicsTextItem

    thanks! calling the function from the child, works...

    Now I'm checking the Qt code and yes, some graphics item have a different implementations of those supposed inherited members :S In my opinion, and it's just my opinion, this is a terrible mistake in the Qt Assistant, because I assume "QGraphicsTextItem" calls directly its parent's function.

Similar Threads

  1. Replies: 1
    Last Post: 8th January 2009, 18:40
  2. drag and drop QToolButton in QToolBar
    By NBilal in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2008, 21:11
  3. Change cursor & status during Drag & Drop
    By ronlongo in forum Qt Programming
    Replies: 0
    Last Post: 1st December 2008, 17:56
  4. Replies: 7
    Last Post: 8th September 2006, 17:19
  5. Drag and drop revisited
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 30th June 2006, 17:41

Tags for this Thread

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.