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
0
votes
1 answer

QMouseEvent for single movement

Why Qt mouse movement event passing multiple event for a single movement? Here is a simple project. mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include #include class MainWindow : public QMainWindow { …
葉翔恩
  • 11
  • 5
0
votes
0 answers

hoverMoveEvent in Qt5 interfering with mousePressEvent

I have a subclassed QGraphicsPixmapItem (item) set to receive hoverMoveEvents and mousePressEvent. When I click on the item without moving my mouse, the hoverMoveEvent is also triggered. What's more problematic is that when I call…
ALH
  • 85
  • 4
  • 14
0
votes
1 answer

How can I recognize QGraphicsView mouse move event?

I am new in qt and c++. I have a qgraphicsview to plot signal. I would zoom specific area with mouse clicking and rectangle drawing. So I need mouse pressed position and dragged position. For this I do such this: in header file: #include…
M.Hu
  • 121
  • 1
  • 14
0
votes
0 answers

Proper way to handle QMouseEvent in Qt

I am currently having a problem for the right click event for QPushButton in the minesweeper game. From what I understand, if I want to give the right click event for the QPushButton, I have to do something like this: In the Buttons Class: class…
Theodore Tang
  • 831
  • 2
  • 21
  • 42
0
votes
1 answer

How to make the QMouseEvent only triggered by MouseButtonPress and to ignore MouseButtonRelease and MouseMove?

I am using a function called InstallEventHandler which takes the name of the event and install handler to it installEventHandler("QWidget", "QMouseEvent","mouse_event") in which the QWidget is the type the the event handler is installed to, the…
Tommy
  • 221
  • 2
  • 7
0
votes
1 answer

How to use mouseMoveEvent on paintEvent on Qt 5?

I'm new on Qt and c++, so I'm having some difficulties. I'm trying to create a widget that can get the mouseMoveEvent position and draw an ellipse on my pixmap on mouse position. Below you can see the code: #include "myimage.h" #include…
Gabriel Schubert
  • 165
  • 4
  • 12
0
votes
2 answers

qt holding mouse button and timer cpp

I dont konw how to connect timers timeout and mouseevent class. I need to draw a new particle in "waterfield" (qwidget) when mouse button is pressed every 200 ms. When i release the button painter should not draw more. I got this in my…
docp
  • 307
  • 1
  • 9
0
votes
1 answer

Qt WebEngine simulate Mouse Event

I want to simulate mouse Event in my Qt WebEngine app. I use PyQt5.8 , QT5.8. This is my code: def mouse_click(self, x, y): point = QPoint(int(x), int(y)) eventp =…
bestren
  • 89
  • 11
0
votes
0 answers

How can I get the text position of a mouse click?

I want to click my mouse on a QTextEdit, and get the text position of that click from within the document. Where would my click be if the click resulted in a character being inserted? I'm hoping to subvert some of QTextEdit's functionality, so I…
0
votes
2 answers

How to detect when JavaFx mouse event occurs in the "label" are of a TitledPane?

I have an Accordian with multiple TitledPanes. When a TitledPane is expanded, there are "dead areas" on the pane that do not have sub-components (e.g., buttons, text, etc.). Right now, when I check MouseEvent.getSource(), it returns an instance of…
SoCal
  • 801
  • 1
  • 10
  • 23
0
votes
1 answer

Using PyQt4.QtGui.QMouseEvent in a QWidget

I am using a PyQt4.QMainWindow as my application interface, and I want to get the x and y coordinates of the mouse inside of a QWidget and set them continuously in 2 textBrowsers in the MainWindow. The documentation for QWidget is here. and the…
Zach G
  • 597
  • 2
  • 10
  • 23
0
votes
1 answer

how can i get Delegate for QTableWidget?

Problem in getting delegates on QTableWidget, I'm trying to use two delegates (comboboxdelegate, spinbox delegate) to control user input in a QTableWidget with 2 columns and one row, but after reading the Delegate Classes page and looking through…
Srikanth Togara
  • 49
  • 2
  • 11
0
votes
1 answer

How can i add new row to the existing QTablewidget

Problem in getting mouseEvent on QTableWidget, this code is to create a window with tabelwidget and mouseclickevent, when i click right button of mouse then i got two action event options named "add" and "delete", i want to add new rows with 3…
Srikanth Togara
  • 49
  • 2
  • 11
0
votes
1 answer

How to draw a Rectangle in Qgraphicsview dynamically (runtime), using Qt4

using QT Creator version 2.4.1. I'm just a starter on QT platform and trying to draw a Rectangle Dynamically. The program uses 3 Mouse events namely mousePressEvent mouseMoveEvent mouseReleaseEvent Problems is mouseMoveEvent is never…
0
votes
2 answers

QStateMachine - QMouseEvent

In another question you tell me to use QStateMachine. I'm new to Qt and it's the first time i use the objects so I make a lot of logical mistake, so using QStateMachine it's a big problem... It's the only way to do thath ? I try to explain my…