PDA

View Full Version : How to move and resize a Application with no title bar and border?



smaranil
16th June 2017, 19:55
i used
w.setWindowFlags(Qt::Window | Qt::FramelessWindowHint); to make the windows boderless and i have Few forms and Tabs on the Application i want to use the bottom left to resize the Window and top Form to move the application

main.cpp

#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;

w.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
w.show();



return a.exec();
}

d_stranz
16th June 2017, 20:35
You need to implement moving and resizing yourself on the MainWindow. Here's how to do the moving. (https://forum.qt.io/topic/34354/frameless-window-dragging-issue)

For resizing, since you have no "grab handles" you need to somehow differentiate between a move operation and a resize operation, because the mouse events on the main window are all you have when there is no frame or title bar. A couple of ideas come to mind: If the mouse down occurs within "x" pixels (say 5) of any of the window's edges, you grow or shrink the window width or height instead of moving it. If it occurs within "x" pixels of both an x and y side (i.e. in a corner) then you resize both width and height. Another option might be to resize when the Shift key is pressed and move otherwise, but this is non-standard behavior.

In any case, you should change the cursor during the operation so the user has some feedback as to what is happening. On the mouse released event, you reset the cursor to normal.