How to disable the resize cursor

I use QWidget::setFixedSize to avoid resizing the window. Despite the fact that it works, the resize style cursor still appears when passing along the edges.

Like this, for example: http://bp3.blogger.com/_fhb-4UuRH50/R1ZMKyoIvMI/AAAAAAAAA6s/I08ntfXpp2k/s1600-h/w-resize.gif

Well, you know what I mean. How can i avoid this?

I am using Windows 7 with the default window manager.

+6
source share
3 answers

If this is your main window and you are using Qt 4, you can disable the sizegrip of the mainwindow status bar:

 this->statusBar()->setSizeGripEnabled(false); 

Otherwise, you can set the Qt::MSWindowsFixedSizeDialogHint in your window:

 this->setWindowFlags(this->windowFlags() | Qt::MSWindowsFixedSizeDialogHint); 
+6
source

First decision

You can add the following flag to the flags of your window so that the user does not resize the window:

 setWindowFlags(this->windowFlags() |= Qt::FramelessWindowHint); 

Here is more information about Flags windows .


The second (ugly) experiment solution

This is a kind of dirty work ... I am fully aware of the fact that it is not clean.

I just wrote this small main window, which changes the cursor manually when the main window area remains.

Note. You should consider side effects. The child widget may need a different cursor shape, but this overrides the cursor for the entire application.

This can be used as a starting point for further development and for simple applications.

Title:

 class CMainWindow : public QMainWindow { public: CMainWindow(QWidget* parent = nullptr); virtual ~CMainWindow(void); protected: virtual void leaveEvent( QEvent *event ); virtual void enterEvent( QEvent *event ); }; 

castes:

 CMainWindow::CMainWindow(QWidget* parent) : QMainWindow(parent) { setMouseTracking(true); } CMainWindow::~CMainWindow(void) { } void CMainWindow::leaveEvent( QEvent *event ) { qApp->setOverrideCursor(QCursor(Qt::ArrowCursor)); QMainWindow::leaveEvent(event); } void CMainWindow::enterEvent( QEvent *event ) { qApp->restoreOverrideCursor(); QMainWindow::enterEvent(event); } 
+2
source

Use

setMinimumSize (QSize (width_px, height_px))

setMaximumSize (QSize (width_px, height_px))

where both methods have the same . You will not see the resize cursor, and the window will thus not be resized / enlarged.

+2
source

Source: https://habr.com/ru/post/952786/


All Articles