PDA

View Full Version : Sorry another problem. Mouse Buttons.



Zephro
20th February 2006, 19:14
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.

wysota
20th February 2006, 19:24
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:


if(event->mouseButtons() & LeftButton){ qDebug("Left pressed"); }
if(event->mouseButtons() & RightButton){ qDebug("Right pressed"); }
if(event->mouseButtons() & (LeftButton|RightButton)){ qDebug("Left and right pressed"); }

Zephro
20th February 2006, 19:29
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

wysota
20th February 2006, 19:31
Backtrace please. With -ggdb. And the code of the event handler. Do you do some type casting there?

Zephro
20th February 2006, 19:34
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....


if(event->mouseButtons() & Qt::LeftButton)
{
std::cout<<"left button\n";
newTree = new TreeNode("||",this->getTree(),labelTree->getTree());

}
else
if(event ->mouseButtons() & Qt::RightButton)
{
std::cout<<"right button\n";
newTree = new TreeNode("&&",this->getTree(),labelTree->getTree());

}
else
{
std::cout<<"ignore\n";
event ->ignore();
return;
}

I'd forgotten the return statement, to stop it trying to do anything with newTree. Hmmm anyhow the if statements aren't working.

wysota
20th February 2006, 19:37
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).

Zephro
20th February 2006, 19:43
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.

wysota
20th February 2006, 19:49
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.

Chicken Blood Machine
20th February 2006, 22:56
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".

wysota
20th February 2006, 23:37
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.

Chicken Blood Machine
20th February 2006, 23:57
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.

wysota
21st February 2006, 10:35
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.

Zephro
21st February 2006, 23:21
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.

orb9
23rd February 2006, 10:15
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?

Zephro
24th February 2006, 16:08
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. ¬_¬