Results 1 to 15 of 15

Thread: Sorry another problem. Mouse Buttons.

  1. #1
    Join Date
    Feb 2006
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Sorry another problem. Mouse Buttons.

    Ok I'm trying to tell the difference between left mouse button drops and right mouse button ones.

    So I'm using the QDropEvent->mouseButtons() method to return errr well I'm not sure, how do I test these flag things exactly?

    I tried if(event->mouseButtons()==Qt::leftMouseButton) which compiles fine but gives a segmentation fault.

  2. #2
    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: Sorry another problem. Mouse Buttons.

    The drop event is not really associated with button types. To be honest, I've never seen a "right mouse button drag".

    If you want to do it anyway, try this way:

    Qt Code:
    1. if(event->mouseButtons() & LeftButton){ qDebug("Left pressed"); }
    2. if(event->mouseButtons() & RightButton){ qDebug("Right pressed"); }
    3. if(event->mouseButtons() & (LeftButton|RightButton)){ qDebug("Left and right pressed"); }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2006
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sorry another problem. Mouse Buttons.

    It's for a uni project. There's icons representing trees, if you drag them ontop of each other you get a union or conjunction based on which mouse button you're holding.

    Ok I tried that, is the & a bitwise operator?

    I'm still getting a segmentation fault from event->mouseButtons() which is a bit odd.... hmmmm

  4. #4
    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: Sorry another problem. Mouse Buttons.

    Backtrace please. With -ggdb. And the code of the event handler. Do you do some type casting there?

  5. #5
    Join Date
    Feb 2006
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sorry another problem. Mouse Buttons.

    Ok nevermind that's embaressing, the segmentation fault is because the if statements are falling through.

    So both the if(event->mouseButtons() & LeftButton)
    and if(event->mouseButtons() & RightButton)

    are failling....
    Qt Code:
    1. if(event->mouseButtons() & Qt::LeftButton)
    2. {
    3. std::cout<<"left button\n";
    4. newTree = new TreeNode("||",this->getTree(),labelTree->getTree());
    5.  
    6. }
    7. else
    8. if(event ->mouseButtons() & Qt::RightButton)
    9. {
    10. std::cout<<"right button\n";
    11. newTree = new TreeNode("&&",this->getTree(),labelTree->getTree());
    12.  
    13. }
    14. else
    15. {
    16. std::cout<<"ignore\n";
    17. event ->ignore();
    18. return;
    19. }
    To copy to clipboard, switch view to plain text mode 

    I'd forgotten the return statement, to stop it trying to do anything with newTree. Hmmm anyhow the if statements aren't working.
    Last edited by Zephro; 20th February 2006 at 19:37.

  6. #6
    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: Sorry another problem. Mouse Buttons.

    Probably because you are letting the buttons go to trigger the event Try keeping the right button pressed while releasing the left one (after causing LMB to start the drag).

  7. #7
    Join Date
    Feb 2006
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sorry another problem. Mouse Buttons.

    Aha, that works. Ta very much.

    Bit counter intuitive, but it's just to demonstrate a presentation idea about trees so it's never going to be really used.

    Also if you happen to know where to find the Fructherman-Reingold algorithm or Kamada-Kawai anywhere let me know! I can only find vague descriptions of the algorithms and I need something to space out the different nodes properly.

  8. #8
    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: Sorry another problem. Mouse Buttons.

    Quote Originally Posted by Zephro
    Aha, that works. Ta very much.

    Bit counter intuitive, but it's just to demonstrate a presentation idea about trees so it's never going to be really used.
    You might want to use "drop actions" instead. There are three such actions -- copy, move and link. You can use them for whatever you want (with copy being the default and two others being triggered by holding ctrl or alt). It might prove simpler.

  9. #9
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sorry another problem. Mouse Buttons.

    Quote Originally Posted by wysota
    The drop event is not really associated with button types. To be honest, I've never seen a "right mouse button drag".
    Windows Explorer is one example. It basically offers you a context menu at the drop site, so that you can choose what you intended - "copy", "move" or "link".
    Save yourself some pain. Learn C++ before learning Qt.

  10. #10
    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: Sorry another problem. Mouse Buttons.

    Quote Originally Posted by Chicken Blood Machine
    Windows Explorer is one example. It basically offers you a context menu at the drop site, so that you can choose what you intended - "copy", "move" or "link".
    But you don't start the drag with RMB, right? I meant dragging with RMB more than dropping with it. Corel Draw has a neat feature -- pressing RMB during the drag modifies its type (causes making a copy of dragged object), even if you release the button before dropping the object, so it's a kind of "during drag" event. I don't know how it is done in Windows Explorer, I rather stay away from it I think you mean something simmilar to what KDE has -- when you drag an object to the desktop a menu pops up asking which action to take. But it is done without using RMB.

  11. #11
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sorry another problem. Mouse Buttons.

    Quote Originally Posted by wysota
    But you don't start the drag with RMB, right?
    Yes you do. (otherwise it would be very fiddly - hold left-button down; drag; press and release right-button during drag - hmmm...).

    I think you mean something simmilar to what KDE has -- when you drag an object to the desktop a menu pops up asking which action to take. But it is done without using RMB.
    No I don't mean that.
    Save yourself some pain. Learn C++ before learning Qt.

  12. #12
    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: Sorry another problem. Mouse Buttons.

    Quote Originally Posted by Chicken Blood Machine
    Yes you do.
    I see.

    (otherwise it would be very fiddly - hold left-button down; drag; press and release right-button during drag - hmmm...).
    That's exactly what Corel does and it's not that bad.

  13. #13
    Join Date
    Feb 2006
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sorry another problem. Mouse Buttons.

    Ok another minor problem

    It is sometimes giving this error when 2 labels merge, possibly something to do with pointers i guess as the amount of objects is changing, but I can't spot a pattern.

    Anyhow the error:
    ASSERT: "heartbeat != -1" in file kernel/qdnd_x11.cpp, line 910

    What does that mean?

    EDIT: Oh and I spent all afternoon getting QT 4.1 installed as that apparantly bug fixed something similar.

  14. #14
    Join Date
    Jan 2006
    Posts
    22
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sorry another problem. Mouse Buttons.

    Quote Originally Posted by Zephro
    Also if you happen to know where to find the Fructherman-Reingold algorithm or Kamada-Kawai anywhere let me know! I can only find vague descriptions of the algorithms and I need something to space out the different nodes properly.
    They are available in the boost library. But prepare for a template ride:
    http://www.boost.org/libs/graph/doc/
    I already tried them and did not manage to parameterize them correctly so my results where somehow useless. Do you know some good documentation for these algorithms?

  15. #15
    Join Date
    Feb 2006
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sorry another problem. Mouse Buttons.

    No idea, I just want a simple description, but detailed enough, so I can implement it myself rather than dealing with templates.

    Especially as my data structures I'm working on probably won't work very well. ¬_¬
    Last edited by Zephro; 24th February 2006 at 16:10.

Similar Threads

  1. Changing mouse grabbing behavior?
    By FlyingSaucrDude in forum Qt Programming
    Replies: 0
    Last Post: 11th November 2008, 01:04
  2. Replies: 7
    Last Post: 20th November 2007, 12:15
  3. Replies: 2
    Last Post: 24th July 2006, 18:36
  4. setCanvas blocks mouse movement on QtCanvasView
    By YuriyRusinov in forum Qt Programming
    Replies: 8
    Last Post: 20th April 2006, 07:38
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.