Results 1 to 5 of 5

Thread: get to focus with mouse on a GLWidget without clicking

  1. #1
    Join Date
    Nov 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default get to focus with mouse on a GLWidget without clicking

    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 :

    Qt Code:
    1. void GLWidget::mouseMoveEvent(QMouseEvent *event)
    2. {
    3. if (event->buttons() & Qt::LeftButton)
    4. {
    5. yrot = (event->x() - xdiff) / 10.0f;
    6. xrot = (event->y() + ydiff) / 10.0f;
    7. }
    8. else
    9. {
    10. event->ignore();
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    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

  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: get to focus with mouse on a GLWidget without clicking

    What exactly is the problem?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: get to focus with mouse on a GLWidget without clicking

    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.

  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: get to focus with mouse on a GLWidget without clicking

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: get to focus with mouse on a GLWidget without clicking

    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.

Similar Threads

  1. Replies: 2
    Last Post: 15th June 2021, 16:00
  2. Replies: 2
    Last Post: 8th October 2010, 07:03
  3. Replies: 0
    Last Post: 30th September 2010, 13:22
  4. QGraphicsItem mouse out of focus
    By bunjee in forum Qt Programming
    Replies: 3
    Last Post: 25th June 2009, 11:45
  5. Mouse events without focus
    By latte in forum Qt Programming
    Replies: 1
    Last Post: 6th February 2007, 12:36

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.