PDA

View Full Version : get to focus with mouse on a GLWidget without clicking



yoti13
28th December 2012, 01:12
I begin with a Qt/OpenGL application. I have a first QMainWindow which contains a GLWidget subclass ("widget_2") of QGLWidget. This GLWidget renders a graphics animation.

From the menu of this QMainWindow, I call a second QMainWindow where I set parameters for the animation of widget_2.

Every works fine except the focus. I would like to have the focus which follows mouse when I move the mouse from a QWindow to another.

I try to use widget_2->setMouseTracking(true) in the constructor of the first QMainWindow but the problem is that I do rotations with mouse on widget_2. So I have overloaded mouseEvent on widget_2 object this way to avoid conflicts between rotations and mouse tracking :


void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton)
{
yrot = (event->x() - xdiff) / 10.0f;
xrot = (event->y() + ydiff) / 10.0f;
}
else
{
event->ignore();
}
}

Currently, when I am on the second QMainWindow and I load the parameters and then I move to the first one, I have still to click on widget_2 GLWidget before being able to do rotations and to press the pushButtons.

I would like the focus to follow mouse, i.e when I am over widget_2, focus is on widget_2 without having to click to do rotations, and when I am over the menu, I don't need to click twice to push buttons.

I am on Debian GNU/Linux 6.0.

Any help would be great

wysota
28th December 2012, 22:18
What exactly is the problem?

yoti13
28th December 2012, 23:05
I want to be able to do rotations directly with mouse on GLWidget without having to click on it the first time that mouse is over this GLWidget.

wysota
28th December 2012, 23:21
I'm assuming that you have tried something and it didn't work. So I'm asking what exact problem are you having with regards to a potential solution you see for the problem. Since you are posting in the "Qt Programming" forum (and not in "Newbie") I'm assuming you have a decent knowledge of Qt and that you tried a number of things before asking here.

BTW. "Focus" is related to keyboard, not mouse.

ChrisW67
29th December 2012, 06:00
What I think you are asking for is for the top-level window that currently has the mouse over it to become the active window. You can probably force this with a call to QWidget::activateWindow() (if isActiveWindow() is false) and possibly raise() in the mouse move handler. Be aware that the behaviour is window manager dependent. This "active window follows mouse" behaviour is typically an option of the window manager (i.e. outside Qt) and you may surprise/annoy the user if their prefernces are click-to-activate.

If that's not what you meant then post a small, complete program the demonstrates the problem.