![]() ![]() system of the widget where this point actually is. Therefore you need to map it to the coord. when using static stuff like QToolTip::show(.) you can be sure, that it will most likely use the global/screen coordinate system. You click (10, 10) in scene- or in some widget's coords, but global (10, 10) is somewhere else. Otherwise something happens like in your initial version. Every time you have different coordinate systems and you want to "sync" them (talking about the same point in both systems). Maybe you need/want to fix it said in Confusion with mouse coordinates:īecause now I am confused when to use mapToScene, mapFromGlobal, maptoGlobal, widgetCoordinates and so on. So the first pixel of the image will not have (0,0), therefore the annotation also wont, but they depend on your scroll factor of your scene. currently they are showing the scene coords. Then it just depends on what your coordinates really need to show. QGraphicsPixmapItem *anotation = new QGraphicsPixmapItem Īnotation->setFlag(QGraphicsItem::ItemIsMovable) Painter->drawText(QRect(0, 0, 50, 50), Qt::AlignCenter, QString::number(num)) Painter->setFont(QFont("Verdana", 21, QFont::ExtraBold)) QTextStream(&stream) setPen(QColor(0, 0, 0, 255)) void QEnhancedGraphicsView::slotPaintMarker(QPoint pos, int num) currently the annoations appear not on the image where you actually click in your scene. Played around a little with your example and draged an image in to test the actual annotation function. QToolTip::showText(this->mapToGlobal(event->pos()), text) QToolTip::showText(event->pos(), text) Global coordinate-system, but widget coord. void QEnhancedGraphicsView::mouseMoveEvent(QMouseEvent *event) The mouseEvent is in widget's coordinates, while you show the QToolTip in global coordinates. If you compare the offset of your clicked point with the annotation, you will set that it's about the same difference.Īfter checking your code. The ToolTip shows up far from the mouse position. All other trademarks are property of their respective owners.Said in Confusion with mouse coordinates: Qt and respective logos are trademarks of The Qt Company Ltd. ![]() MOUSE COORDINATES IN QT SOFTWAREThe documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. On QEvent::HoverEnter events, this position will always be QPointF(-1, -1).ĭocumentation contributions included herein are the copyrights of If there is no previous position, oldPosF() will return the same position as posF(). Returns the previous position of the mouse cursor, relative to the widget that received the event. On QEvent::HoverEnter events, this position will always be QPoint(-1, -1). If there is no previous position, oldPos() will return the same position as pos(). modifiers hold the state of all keyboard modifiers at the time of the event. The pos is the current mouse cursor's position relative to the receiving widget, oldPos is its previous such position, and globalPos is the mouse position in absolute coordinates. The type parameter must be QEvent::HoverEnter, QEvent::HoverLeave, or QEvent::HoverMove. Member Function Documentation QHoverEvent:: QHoverEvent( QEvent::Type type, const QPointF & pos, const QPointF & globalPos, const QPointF & oldPos, Qt::KeyboardModifiers modifiers = Qt::NoModifier, const QPointingDevice * device = QPointingDevice::primaryPointingDevice())Ĭonstructs a hover event object originating from device. A::HoverMove, B::HoverMove, C::HoverMove.In this case the events will occur in the following way: It will only stop propagating with the Qt::WA_NoMousePropagation attribute. You will get the same events for QEvent::HoverMove, except that the event always propagates to the top-level regardless whether the event is accepted or not. Now, if you move the cursor from the top to the bottom in the middle of A, you will get the following QEvent::MouseMove events: Let us consider a top-level window A containing a child B which in turn contains a child C (all with mouse tracking enabled): QEvent::HoverMove is also slightly different from QEvent::MouseMove. ![]() ![]() However, they are slightly different because we do an update() in the event handler of HoverEnter and HoverLeave. There are a few similarities between the events QEvent::HoverEnter and QEvent::HoverLeave, and the events QEvent::Enter and QEvent::Leave. The function pos() gives the current cursor position, while oldPos() gives the old mouse position. Mouse events occur when a mouse cursor is moved into, out of, or within a widget, and if the widget has the Qt::WA_Hover attribute. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |