Mouse position and a QDialog - qt

I am trying to figure out if there is a way to make a qdialog to input the co-ordinates of a line such that the co-ordinates can be given by mouse position or a qdialog (via QLineEdit items). Is there a way to have the mouse position be displayed in the QLinedEdit items in the qdialog when moving the mouse of the canvas or move the line points when typing in the dialog?
Thanks.

Related

QDialog as top-level window doesn't work

I have a main QWindow and a QFrame (mainF) on it, which contains some other gui elements. I maximize the QFrame as follows, if I click on a button on my QWindow:
mainF->setWindowFlags(Qt::Dialog);
mainF->setWindowState((mainF->windowState(), Qt::WindowFullScreen));
mainF->show();
To minimize the QFrame and place it in its previous position again, I have created a QDialog (m_MinimizeFullscreenGui) with a button on it, which appears immediately on the right top corner of my QFrame if I maximize it:
QRect windowRectangle= m_MinimizeFullscreenGui->geometry();
WindowRectangle.moveTopRight(QApplication::desktop()->availableGeometry().topRight());
m_MinimizeFullscreenGui->setGeometry(windowRectangle);
m_MinimizeFullscreenGui->setFixedSize(30, 30);
m_MinimizeFullscreenGui->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
m_MinimizeFullscreenGui->setWindowState(m_MinimizeFullscreenGui->windowState());
m_MinimizeFullscreenGui->show();
The problem is: I want to have my small dialog window always on the top-level of my maximized QFrame. But if I click at somewhere on my QFrame, the dialog window goes in the background, so the Qt::WindowStaysOnTopHint flag doesn't work.
Where can be my mistake?

how to position a tooltip in qt graphicsview

I want to show a tooltip when dragging the endpoint of a line to a QGraphicsItem with the mouse pointer (no hovering).
So i have the mouse event and i want to call QToolTip::showText(QPoint pt, String str) and i want to show the tooltip at a normal position relative to the mouse pointer.
But whatever i try (widget.mapToGlobal, item.mapToScene) on event.pos() the tooltip appears realtive to the topleft of my screen or the graphicsview, not the mouse.
Maybe i am missing something simple, but i would really appreciate some help with this.
widget = item.scene().views()[0] #there is only one view
p = event.pos()
pt = widget.mapToGlobal(QtCore.QPoint(p.x(), p.y()))
QtGui.QToolTip.showText(pt, text)
QGraphicsSceneMouseEvent has another useful method - screenPos() which returns the mouse cursor position in scene coordinates. Try to use it. For example:
QtGui.QToolTip.showText(event.screenPos(), text)

How to fix the position of QGraphicsItem and making only the QGraphicsTextItem to move?

I have a QGraphicsView in which I am painting a QGraphicsItem and QGraphicsTextItem.
I have set the flag ItemIsMovable for the QGraphicsTextItem for editing the long text.
Here my concern. When I am moving the QGraphicsTextItem to view the long text, it is also moving the QGraphicsText to left.
But I want only the QGraphicsTextItem to be movable.
I want to fix the position of QGraphicsItem? How do I do that?
Edit:
Here is the output of my code. I have this QGraphicsView at the top-left of my application. The Viewport of this QGraphicsView is the width of the QGraphicsItem.
When I click on the QGraphicsTextItem and move the cursor to the right to view the text, the QGraphicsItem also moves and becomes hidden as shown in the image.
How do I fix the position of this QGraphicsItem?

How to have QGraphicsScene not centered in QGraphicsView

How can I manualy position a QGraphicsScene inside the QGraphicsView, because the default is always centered, but I want to position it by myself.
Call the centerOn function of QGraphicsView
Scrolls the contents of the viewport to ensure that the scene coordinate pos, is centered in the view.
Alternatively, if you want to specify a rect of the area in the scene to be visible, you can use fitInView.

Qt: How to create/render Arrow Graphics Item on QGraphicsscene

How do we create a Arrow graphics item which gets displayed on a graphics scene?
My requirement is that I drag and drop a QGraphicsLineItem from one scene to another. Once the Line item is dropped on a scene, a Arrow graphics Item should display perpendicular to the line item dropped on the scene. I should be able to display the Arrow Item on either side of the line. Currently I am able to drop a Line item onto the scene. I need source code for creation of an Arrow item.
Can somebody please help me with this scenario?
There are two possible options here. One is to have an image that you load into a QGraphicsPixmapItem and position and rotate it as desired.
The better method would be to create a class inherited from QGraphicsItem, and draw the arrow in its paint method, with the calls to drawLine.
When you inherit from QGraphicsItem, make sure that you overload the boundingRect() function, as well as the paint() function.

Resources