Results 1 to 8 of 8

Thread: Question about the MouseMoveEvent of qtdemo's TextButton

  1. #1
    Join Date
    Sep 2010
    Posts
    5
    Platforms
    Unix/X11 Windows
    Thanks
    2

    Question Question about the MouseMoveEvent of qtdemo's TextButton

    When I was add "item->setFlags(QGraphicsItem::ItemIsMovable);" in menumanager.cpp

    First, One can move to what the mouse move.But second time to move the item,it will jump to the Original pos of first time.

    What the problem is ?
    Last edited by yzdying; 19th February 2011 at 04:33. Reason: updated contents

  2. #2
    Join Date
    Sep 2010
    Posts
    5
    Platforms
    Unix/X11 Windows
    Thanks
    2

    Default Re: Question about the MouseMoveEvent of qtdemo's TextButton

    Nobody know?

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

    Default Re: Question about the MouseMoveEvent of qtdemo's TextButton

    Speaking only for me, I just don't understand what you wrote.
    Try to explain more in details, and add code.
    ==========================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.

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

    yzdying (22nd February 2011)

  5. #4
    Join Date
    Sep 2010
    Posts
    5
    Platforms
    Unix/X11 Windows
    Thanks
    2

    Default Re: Question about the MouseMoveEvent of qtdemo's TextButton

    Think you high_flyer, My English is no good,
    I would like to use MouseMoveEvent event of Textbutton, so that I can drag the item to the specified location.
    I add the flag "QGraphicsItem::ItemIsMovable" to item in menumanager.cpp

    Qt Code:
    1. void MenuManager::createMenu(const QDomElement &category, BUTTON_TYPE type)
    2. {
    3. .........
    4.  
    5. // create normal menu button
    6. QString label = currentNode.toElement().attribute("name");
    7. item = new TextButton(label, TextButton::LEFT, type, this->window->scene, this->window->mainSceneRoot);
    8. currentNode = currentNode.nextSibling();
    9.  
    10. item->setFlags(QGraphicsItem::ItemIsMovable);
    11.  
    12. .........
    13. }
    To copy to clipboard, switch view to plain text mode 
    First, Drag a item to specified location . When I click the leftbutton and start to drag the item,it will jump to (0 ,0) before the mouse moving.

    I drag dowm a item from the location of (59, 233) to the specified location of (59, 236);
    drag item pos output:
    QPointF(59, 233)
    QPointF(0, 1)
    QPointF(0, 2)
    QPointF(0, 3)

    As you can see, the moving graber jump from (59, 233) to (0, 1).

    So I don't know what cause this result.

    You can have a try to drag.
    Last edited by yzdying; 22nd February 2011 at 02:51.

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

    Default Re: Question about the MouseMoveEvent of qtdemo's TextButton

    Please provide the code that deals with the moving, and setting of coordinates.
    ==========================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.

  7. #6
    Join Date
    Sep 2010
    Posts
    5
    Platforms
    Unix/X11 Windows
    Thanks
    2

    Default Re: Question about the MouseMoveEvent of qtdemo's TextButton

    Qt Code:
    1. void TextButton::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
    2. {
    3. qDebug() << pos();
    4. QGraphicsItem::mouseMoveEvent(event);
    5. }
    To copy to clipboard, switch view to plain text mode 
    Only to add the pos output. and Nothing modited to the qtdemo source besides added the ItemIsMovoble flag;

    the moving graber is in scene coordinates
    Last edited by high_flyer; 22nd February 2011 at 14:23. Reason: code tags

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

    Default Re: Question about the MouseMoveEvent of qtdemo's TextButton

    But where is the code that sets the position in your code?
    ==========================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.

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

    yzdying (23rd February 2011)

  10. #8
    Join Date
    Sep 2010
    Posts
    5
    Platforms
    Unix/X11 Windows
    Thanks
    2

    Default Re: Question about the MouseMoveEvent of qtdemo's TextButton

    Thanks again!
    Qt Code:
    1. //TextButton.cpp
    2. void TextButton::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
    3. {
    4. qDebug() << pos();
    5. QGraphicsItem::mouseMoveEvent(event);
    6. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. menumanager.cpp
    2. void MenuManager::createMenu(const QDomElement &category, BUTTON_TYPE type)
    3. {
    4. .........
    5.  
    6. // create normal menu button
    7. QString label = currentNode.toElement().attribute("name");
    8. item = new TextButton(label, TextButton::LEFT, type, this->window->scene, this->window->mainSceneRoot);
    9. currentNode = currentNode.nextSibling();
    10.  
    11. item->setFlags(QGraphicsItem::ItemIsMovable); ///this line is my added
    12.  
    13. .........
    14. }
    To copy to clipboard, switch view to plain text mode 


    Only modified two places in the source of qtdemo.
    But course that the moving item jump from (59, 233) to (0, 1) in the procedure of qtdemo.

Similar Threads

  1. QtDemo
    By Raymond in forum Qt Programming
    Replies: 7
    Last Post: 22nd April 2010, 12:52
  2. qtdemo question
    By link in forum Qt Programming
    Replies: 4
    Last Post: 24th February 2009, 18:04
  3. qtdemo 4.4 looks like this on my machine!
    By magland in forum General Discussion
    Replies: 1
    Last Post: 25th May 2008, 08:55
  4. QGraphicsScene::mouseMoveEvent Question
    By harakiri in forum Qt Programming
    Replies: 3
    Last Post: 3rd March 2008, 15:54
  5. How to get qtdemo with reasonable speed?
    By ponto in forum General Discussion
    Replies: 8
    Last Post: 31st May 2006, 11:25

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.