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
2 answers

QT: Select multiple QTableWidgetItems from code with QMouseEvent

it's my first question here on stackoverflow, but not the first time you help me out (I hope you can). First I have to mention that I'm not that experienced with C++, especially with QT, where my problem is about. I have a problem with posting (or…
Jack
  • 11
  • 3
0
votes
1 answer

Implementing freely dragging the scene in graphics-view

I would like to implement a free dragging functionality based on C++ Qt's graphics-view. However, I need to achieve this without changing the sceneRect and without using view->setDragMode(QGraphicsView::ScrollHandDrag) , as some of my business logic…
super chen
  • 11
  • 4
0
votes
1 answer

How to enable mouse tracking on a QLabel that has RichText

I really want a single QLabel to have different colours for different parts of the string. Past questions have led me to the solution of using HTML4 rich text options within it, for example: 'I\'m red!
0
votes
0 answers

Why tracking QMouseEvent in my custom slider is being triggered unpredictably?

I'm working on a custom slider on Qt, so I have a widget and a Slider in it promoted to my class called CustomSlider. In this class I'm using PaintEvent to draw some markers and an EventFilter to catch the mouse when hovers over those markers to…
BinaryTalk
  • 33
  • 5
0
votes
1 answer

How can child widget capture the mouse event under such circumstance

I need to simulate drag and drop in Qt, but I'm facing a problem. Here is the simplified version of the problem: here you can see the action I took. I pressed the mouse in the area of parent widget and moved it to a child widget, keeping pressing,…
0
votes
1 answer

PyQt5: QGraphicsScene: Mouse item with click and drop (without holding press)

The default mouseEvent function in QGraphicsScene allows to move the Item by press-and-hold, move, and release. I am trying to overwrite the QGraphicsScene mouseEvent() function to accomplish the same movement with press-and-release-once (pick…
0
votes
1 answer

Drawing Line from QLabel to QLabel in PyQt

I'm fairly new to PyQt I'm trying to drawing a line from 1 QLabel to another. My 2 QLabel are located on another QLabel which acts as an image in my GUI. I've managed to track the mouse event and move the label around, but I cannot draw the line…
Michael
  • 11
  • 4
0
votes
1 answer

Getting mouse position relative to image limits

I display an image within a custom QLabel and get clicks on this label. I'm interested in clicks within the image only, and in a position expressed by a number between 0 and 1, 0 being the leftmost or topmost pixel and 1 the rightmost or bottommost…
mins
  • 6,478
  • 12
  • 56
  • 75
0
votes
1 answer

QMouseEvent is of type 5? What is type 5?

I have a Widget that has mouseTracking set to True and the following code prints 5, even though I'm not pressing any buttons. Additionally type 5 isn't mentioned in the MouseButton enum docs. So what is type 5 and why is the mouseEvent of type…
Legatio
  • 259
  • 3
  • 9
0
votes
1 answer

How to implement mousePressEvent (QMouseEvent * event) inside a class?

Good day. Dealing with QMouseEvent. Made a project with its own class, which implements a player based on QMovie. #ifndef QTUBE_H #define QTUBE_H #include #include #include class QNewScene; class QTube : public…
Anton1978
  • 35
  • 7
0
votes
1 answer

How to use QMouseEvent to display the mouse position in a QChart?

I am pretty new on Qt and C++. I have a QChart which has a QLineSeries object. I want to show the user the projection of the mouse on the coordinate system. My problem is I can display coordinates everywhere except my QChart object. I want to…
0
votes
1 answer

Qt : how to action_triggered then use QMouseEvent?

I'd like to do something like this, even though I understand this is not how it works. I'm not really good with QMouseEvent, void MainWindow::on_addState_triggered(QMouseEvent* event) { qDebug() << event->pos(); if (event->buttons() ==…
DevOops
  • 117
  • 11
0
votes
0 answers

Why mousePressEvent is not called when I click MiddleButton of mouse on Combobox popup?

I am using Qt Creator and C++ for my code. I have a checkable combobox for multiselection. I want to select the unchecked checkbox using mouse Middlebuton from popup. I tried to override the mousePressEvent but didn't work. Below is the snippet of…
0
votes
1 answer

Getting a Qt Widget to update a mouse event inside a Qt form made with Qt Designer

I have made a custom QGraphicsView that I'm adding as a widget into an app form I made using Qt Designer. Everything appears to be working including the mouse clicks. The method that does the drawing gets called but I'm having trouble getting to…
user3023715
  • 1,539
  • 2
  • 11
  • 12
0
votes
1 answer

QMouseEvent for single movement on QWidget

Why QMouseEvent passing multiple events for single movement on QWidget? I'm implementing simple dragging effect, but the result is not what I expected. The following code will move the widget to new location but instantly move it back to the…
葉翔恩
  • 11
  • 5