How to draw a transparent area selection box
-
I have a
QPushButton
connected to a slot that minimizes myQMainWindow
. After minimizing the window, I intend to draw a transparent rectangular box with only a border. The purpose is to create a selection box, similar to how screen capture apps function where they allow the user to select an area on their screen and display a width and height in the middle. I aim for users to drag and resize this box using their mouse. Is there an example demonstrating this functionality in QtWidgets version 6.6.1? -
@JonB said in How to draw a transparent area selection box:
Can/how you tell QWidgets to go outside the application window?
QRubberBand
is a widget itself and you can show it any time.Maybe even a
QRubberBand
subclass with an inbuilt timer to update the mouse pos (QCursor::pos
) of the drag (because no parent window/widget = nomouseMoveEvent
) ;-) -
@Pl45m4
I don't know the answer to this. The OP (if I understand right) wants to draw a box on the screen/desktop, outside of the Qt application (that is minimized). Can/how you tellQWidget
s to go outside the application window? Do you create a widget with no parent and screen coordinates and that's allowed? -
@JonB said in How to draw a transparent area selection box:
Can/how you tell QWidgets to go outside the application window?
QRubberBand
is a widget itself and you can show it any time.Maybe even a
QRubberBand
subclass with an inbuilt timer to update the mouse pos (QCursor::pos
) of the drag (because no parent window/widget = nomouseMoveEvent
) ;-) -
-
-
-
@Pl45m4 said in How to draw a transparent area selection box:
Maybe even a
QRubberBand
subclass with an inbuilt timer to update the mouse pos (QCursor::pos
) of the drag (because no parent window/widget = nomouseMoveEvent
) ;-)A timer shouldn't be necessary. Implement the mouse events in the subclass. The QRubberBand, being a widget without a parent, will create its own window.
-
But then you only have the mouseMoveEvents where the rubberband already is and not where you want to move it, right?!
You want to track the mouse pos over the whole screen and then click and drag to adjust the rectanhe to capture or do whatever you like -
@Pl45m4 said in How to draw a transparent area selection box:
But then you only have the mouseMoveEvents where the rubberband already is and not where you want to move it, right?!
That's true, if there is no rubber band window to start. I was thinking of the macOS screen capture interface that opens with the previously used geometry, or a default for the first use.
If there's no initial underlying window belonging to the application, the
window managerwindowing system is going to have to cooperate and not deliver the mouse button press to something else. -
@jeremy_k said in How to draw a transparent area selection box:
If there's no initial underlying window belonging to the application, the window manager is going to have to cooperate and not deliver the mouse button press to something else.
That's the sort of thing I was thinking of. I didn't know plain applications had access to the visual desktop, only to the windows the manager allowed it to create. But I don't really know.