Questions tagged [qmouseevent]

The QMouseEvent class contains parameters that describe a mouse event.

The QMouseEvent class contains parameters that describe a mouse event.

Mouse events occur when a mouse button is pressed or released inside a widget, or when the mouse cursor is moved.

Mouse move events will occur only when a mouse button is pressed down, unless mouse tracking has been enabled with QWidget::setMouseTracking().

Qt automatically grabs the mouse when a mouse button is pressed inside a widget; the widget will continue to receive mouse events until the last mouse button is released.

A mouse event contains a special accept flag that indicates whether the receiver wants the event. You should call ignore() if the mouse event is not handled by your widget. A mouse event is propagated up the parent widget chain until a widget accepts it with accept(), or an event filter consumes it.

Note: If a mouse event is propagated to a widget for which Qt::WA_NoMousePropagation has been set, that mouse event will not be propagated further up the parent widget chain.

The state of the keyboard modifier keys can be found by calling the modifiers() function, inherited from QInputEvent.

The functions pos(), x(), and y() give the cursor position relative to the widget that receives the mouse event. If you move the widget as a result of the mouse event, use the global position returned by globalPos() to avoid a shaking motion.

The QWidget::setEnabled() function can be used to enable or disable mouse and keyboard events for a widget.

Reimplement the QWidget event handlers, QWidget::mousePressEvent(), QWidget::mouseReleaseEvent(), QWidget::mouseDoubleClickEvent(), and QWidget::mouseMoveEvent() to receive mouse events in your own widgets.

Reference: http://qt-project.org/doc/qt-4.8/qmouseevent.html

90 questions
1
vote
1 answer

Get absolute mouse click location on widget (also when zoomed in) Qt

I want to trigger where I click with the mouse on my QGraphicsView. Problem here: this QGraphicsView is always zoomed in. But I want to get the point relative to the whole widget and not only to the viewport. Or in other words: when I zoomed in and…
mep
  • 341
  • 2
  • 11
1
vote
0 answers

Selecting ROI for high resolution images with Qt and Opencv

I am working on a project that involves selecting an ROI from high resolution image(more like 5187x3268 like that). Right now i am using findContours in OpenCV to detect a round object(since hough circles is kind of slow for high res images). The…
the_parzival
  • 354
  • 3
  • 19
1
vote
0 answers

How to send aQMouseEvent to QWebEngineView?

Context: I'm creating a web browser. I need to send mouse events to the web page. It was working with Qt WebKit, but now some sites doesn't work with QT WebKit. So, I need to move my web brouser to Qt WebEngine. But my old solution for QMouseEvent…
howc0me
  • 11
  • 1
1
vote
2 answers

How to recognize QMouseEvent inside child widgets?

EDIT and Some Self Critisicm I tried both given solutions, which both solved my problem, and thus I thank you both! I marked the transparent solution as accepted because I thought it is was the easiest implementation when I only had one child…
Wololo
  • 1,249
  • 1
  • 13
  • 25
1
vote
1 answer

QWidget::mousePressEvent() on two widgets at once

I'm trying to run two QWidget::mousePressEvent() handlers at once. I have two widgets, A and B. B is inherited from QLabel, A from QWidget. I have overloaded QWidget::mousePressEvent() on both of them. Widget from B is getting QPoint cursor…
Tatarinho
  • 754
  • 2
  • 11
  • 31
1
vote
2 answers

Make QML Item/Control accept events thus not forwarding them to parent

I inherited QQuickWindow and created a frame-less window that can be moved by drag. Inside my window I put a Slider element. The problem is that the Slider forwards the events to the parent window and when I try to change the value on the slider,…
Jacob Krieg
  • 2,834
  • 15
  • 68
  • 140
1
vote
1 answer

Unexpected behaviour with QMouseMoveEvent and QKeyEvent modifiers

I am encountering unexpected behaviour in my code. I have a QGraphicsView containing a QGraphicsScene. Now I want to detect the mouse wheel for zooming the view and mouse moving for moving items in the scene, the latter only while controll is…
honiahaka10
  • 772
  • 4
  • 9
  • 29
1
vote
1 answer

"error: C2275: 'QMouseEvent' : illegal use of this type as an expression"

'I am currently having an issue tryinh to compile this program. The program is supposed to show the coordinates of the mouse on a GUI QWidget The error is in line 6 of the mainwindow.cpp file' //header #ifndef MAINWINDOW_H #define…
JLREng
  • 13
  • 4
1
vote
1 answer

Qt: change QGraphicsItem receiver during mouse move

I am currently trying to implement a Bezier pen tool. The course of events looks like this: click on point (QGraphicsItem), start moving while clicked in QGraphicsScene mouseMoveEvent, prevent moves of point (with a boolean flag) until when…
blameless75
  • 2,148
  • 2
  • 19
  • 14
1
vote
2 answers

graphicsview receives mouse event before the item

I have implemented the panning view on the QGraphicsView, using the mouse move event using void View::mouseMoveEvent(QMouseEvent* event) { pan(); QGraphicsView::mouseMoveEvent(event); } and in the scene of this view I have added few items where…
Wagmare
  • 1,354
  • 1
  • 24
  • 58
1
vote
1 answer

How can I access protected member in QMouseEvent to get a float value of mouse position ? [Qt developers]

QMouseEvent stores an integer value of the mouse position. However, it has a protect member "s" which stores a float value of the mouse position. How can I get the float value? I have tried inheriting the QMouseEvent, but unfortunately I get this…
Nai
  • 71
  • 7
1
vote
1 answer

Qt: QMouseEvent not propagating out of QGLWidget

Is it possible for the QGLWidget to propagate its mouse event? I currently have a QGlWidget as a child of my main window, but I can't seem to handle the mouse events occurring over it's frame. Perhaps I'm making a fundamental flaw, but the mouse…
Yattabyte
  • 1,280
  • 14
  • 28
1
vote
3 answers

PyQt mousePressEvent - get object that was clicked on?

I'm using PyQt and PyQtGraph to build a relatively simple plotting UI. As part of this I have a graphicsview (pyqtgraph's graphicslayoutwidget) that has PlotItems dynamically added to it by the user. What I'm trying to achieve is allowing the user…
dan_g
  • 2,712
  • 5
  • 25
  • 44
1
vote
0 answers

Qt - Pass a QMouseEvent to child wildgets

I have do some research about QMouseEvents but I am stuck about passing a QMouseEvent to child widgets. I have a program with a structure like this : MainWindow > DockWidget > WidgetList > WidgetTarget MainWindow is parent of DockWidget etc... My…
user3627590
  • 281
  • 1
  • 4
  • 10
1
vote
1 answer

Movable QRubberband from one point to another

I have drawn a QRubberband on QLabel. i can resize it using QSizeGrip. Now I want to move it from one point to another using QMouseevents. Is there any one who can help me out. void CropImage::mousePressEvent(QMouseEvent *event) { …
Ashish
  • 219
  • 2
  • 6
  • 22