Docking and moving a frameless window?
-
So i used the frameless window hint to remove the titlebar and implemented a custom menubar which lets me move, maximise, minimize and close the window.
However when i move very fast the window sometimes gets stuck somehow, but i couldn't figure out why and what im doing wrong?
Also i couldn't figure out how to make the window dock/snap when being dragged to the sides or far top or bottom:#include "CustomMenubar.h" #include <QApplication> #include <QMouseEvent> CustomMenuBar::CustomMenuBar(QWidget *parent) : QMenuBar{parent} { } void CustomMenuBar::mousePressEvent(QMouseEvent *event) { QAction *action = actionAt(event->pos()); if (action && action->menu()) { // If a MenuItem with a submenu is clicked, we won't start moving the window clickedOnMenuItem = true; isMoving = false; QMenuBar::mousePressEvent(event); } else { QMenuBar::mousePressEvent(event); pressPos = event->globalPosition(); isMoving = true; event->accept(); } } void CustomMenuBar::mouseReleaseEvent(QMouseEvent *event) { QAction *action = actionAt(event->pos()); if (action && action->menu()) { QMenuBar::mouseReleaseEvent(event); return; } // If the mouse was being used for dragging, stop moving if (isMoving) { isMoving = false; event->accept(); } } void CustomMenuBar::mouseMoveEvent(QMouseEvent *event) { QAction *action = actionAt(event->pos()); if (action && action->menu()) { QMenuBar::mouseMoveEvent(event); return; } // If the mouse was pressed and is moving, move the window if (isMoving) { QMenuBar::mouseMoveEvent(event); QPointF diff = event->globalPosition() - pressPos; QWidget *window = QApplication::topLevelAt(pressPos.toPoint()); if (window && window->isWindow()) { window->move(window->pos() + diff.toPoint()); pressPos = event->globalPosition(); event->accept(); } } }
Thanks in advance. :) Have a nice evening.
-
But we are already dealing with a
QDockWidget
, aren't we?
AFAIK you can only dockQDockWidgets
and its subclasses.Has your
QMainWindow
and/or window alldockAreas
enabled? -
@Pl45m4 No i don't mean a qdockwidget i mean the docking behaviour of window. Like normally you can append a window to a side of the screen like splitscreen, so another application can fit on the other side.
When calling frameless window this ability gets lost so i was looking for a way to manually recover it. Any idea?
-
This?
It's called Split Window / Window Tile or something like that and is a Window Manager functionality (in your case, X on Windows 7/10).
Because frameless Qt toplevel Widgets don't request a Window decoration, I think X does not recognize that you want to snap/split it anyway.
This is probably not doable with Qt only and platform/Window Manager dependent, maybe you need some extension. Haven't found one though.Edit:
If you are fine with not using the native functionality, you could try to implement something like that using your Qt widget... when enabled, calculate the requested area (1/2, 1/4...) of your screen size and geometry and resize + move your widget accordingly.