Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWidget::enterEvent is not being triggered when mouse button is pressed

QWidget::enterEvent is not being triggered when mouse button is pressed

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jaskmar
    wrote on last edited by
    #1

    I am implementing custom QSplitterHandle which I want to get working some different way. I have to handle situation when user starts dragging over SplitterHandle widget. But it does not work when the mouse button is pressed.
    The question is how can I handle that.

    Constructor:
    @
    BetterSplitterHandle::BetterSplitterHandle(Qt::Orientation orientation, QSplitter * parent) :
    QSplitterHandle(orientation, parent)
    {
    setMouseTracking(true);
    }
    @

    current implementation for event:
    @
    void BetterSplitterHandle::enterEvent(QEvent *event)
    {
    qDebug("b"); //works only when mouse buttons are released
    }
    @

    I have try dragEnterEvent, but it doesn't work neither.

    PS: Sory for my english :)

    1 Reply Last reply
    0
    • jeremy_kJ Online
      jeremy_kJ Online
      jeremy_k
      wrote on last edited by
      #2

      Off hand, this sounds like a mouse grab issue. When a button is clicked, Qt grabs all mouse input and sends it to the widget that the cursor was over when the button was clicked.

      http://qt-project.org/doc/qt-4.8/qwidget.html#grabMouse

      Perhaps an event filter will do the job without too much work.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jaskmar
        wrote on last edited by
        #3

        [quote author="jeremy_k" date="1411939385"]Off hand, this sounds like a mouse grab issue. When a button is clicked, Qt grabs all mouse input and sends it to the widget that the cursor was over when the button was clicked.[/quote]

        OK, perhabs you are right, but the main problem is where (inside which event) should I call the grabMouse method?

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jaskmar
          wrote on last edited by
          #4

          OK, I found solution (or maybe it is only workaround) with jeremy's tip - I have reimplemented mouseMoveEvent of parent's widget (in my case it is QSplitter's child class):

          @
          void SidebarsLayout::mouseMoveEvent(QMouseEvent *event)
          {
          if (event->buttons() | Qt::LeftButton) {
          if (event->pos().x() < width()/2) {
          firstHandle()->grabMouse();
          } else {
          lastHandle()->grabMouse();
          }
          }
          }
          @

          As you can see this is not perfect solution, as only one SplitterHandle can grab mouse events at time, and I have to calculate which one. In my case it is satisfactory, but if someone have better solution, I would like to see it.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved