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.
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:
Code:
if(event->mouseButtons() & LeftButton){ qDebug("Left pressed"); }
if(event->mouseButtons() & RightButton){ qDebug("Right pressed"); }
if(event->mouseButtons() & (LeftButton|RightButton)){ qDebug("Left and right pressed"); }
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
Re: Sorry another problem. Mouse Buttons.
Backtrace please. With -ggdb. And the code of the event handler. Do you do some type casting there?
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....
Code:
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.
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).
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.
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.
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".
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.
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...).
Quote:
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.
Re: Sorry another problem. Mouse Buttons.
Quote:
Originally Posted by Chicken Blood Machine
Yes you do.
I see.
Quote:
(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.
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.
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?
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. ¬_¬