How to enable resizing of a frameless widget
What to write here:
- {
- //what to write here
- }
15 replies
Nothing special. That method is called when the widget is already being resized. I guess your problem is how to actually make the widget resizable. By far the easiest way to do that, is to just give the widget a frame and let the window system handle it for you. Otherwise, look into using QSizeGrip.
I have already tried QSizeGrip, it is working fine but the issue is that it appears on the top left corner instead of bottom right which is cuasing some specific problem. As per Qt- Doc a frameless window does not support resizing or even dragging. But we can re-implement the mouseMoveEvent and resize events to enable that too. Now, what i want is code for resizing:
- {
- setStyleSheet("background-color: rgba(0, 0, 0, 40%)");
- setScaledContents(true);
- setWindowOpacity(.900);
- setFrameStyle(2);
- }
- {
- dragPosition = event->globalPos() - frameGeometry().topLeft();
- event->accept();
- }
- }
- {
- move(event->globalPos() - dragPosition);
- topPos=event->globalPos() - dragPosition;
- event->accept();
- }
- }
- {
- //what to write here
- }
Is this the same issue as the one you’re discussing in this topic?
Perhaps, yes. As no one replied to my my query yesterday, I figured out a way myself, but got stuck with other problem. So, i asked this question to completely change the way of resizing. The code is same, but i want to use resizing event as it enables resizing from every side and Qsizegrip allows resizing only from one corner
You need to practice more patience. Please recognize that it is Easter weekend, and lots of people are enjoying time off with their families. At least have patience until, say Wednessday before you start thinking that your topic is being ignored. It is not good practice to open multiple parallel topics that are really about the same thing in any case.
What to write here: @void CropFrame::resizeEvent(QResizeEvent *event) { //what to write here }@
You need to call resize() or setGeometry() to change the size of your widget.
resizeEvent() doesn’t do such things, this is similer to mousePressEvent() which is called when you press your mouse, but it doesn’t press mouse by itself.
you can call resize() when your mouse pressed —> moved —> released.
If we consider any normal widget, just by moving the mouse to the boundary changes the shape of cursor, and we can resize that widget, can’t we just restore the same resizing ability with same features of cursor shape change etc. in frameless widgets.
Besides, i am using mousepressevent for draging
- {
- dragPosition = event->globalPos() - frameGeometry().topLeft();
- event->accept();
- }
- }
Alright, i don’t wish to lenghten this discussion: QSizeGrip is working fine but has one issue, if you can resolve the issue the story ends here, no need of resizing using resizing event. I don’t have much experience in event handling.
Actually the above Qlabel variant that is CropFrame class, I am using to mark the region for cropping. It is actually for selecting the area for cropping. For cropping i am passing the top left co-ordinates and height and width of CropFrame object. In mousemoveEvent i am storing the top left co-ordinates in- topPos=event->globalPos() - dragPosition;
- {
- move(event->globalPos() - dragPosition);
- topPos=event->globalPos() - dragPosition;
- event->accept();
- }
- }
You must log in to post a reply. Not a member yet? Register here!




