6

I use QWidget::setFixedSize to avoid my window being resized. Even though it works, the resize-style cursor still appears when passing over 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 that?

I use Windows 7 with the default windows manager.

  • Interesting question. I am not even sure this is possible. Isn't this a function of the window manager? It **could** be that Qt does not have control over this cursor. Perhaps you should add more tags to your question. 'windowmanager'? What OS? What window manager do you use? Might need another kind of expertise to solve your problem then you think. – Greenflow Aug 29 '13 at 21:49
  • Not sure - does setting the window flag to `Qt::Dialog | QT::Window` do anything? – NG. Aug 29 '13 at 21:49
  • Is this for your mainwindow? Which Qt version are you using? – thuga Aug 30 '13 at 07:07

3 Answers3

11

If this is your mainwindow and you're using Qt 4, you can disable the sizegrip of your mainwindow's statusbar:

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

Otherwise you can set the Qt::MSWindowsFixedSizeDialogHint flag to your window:

this->setWindowFlags(this->windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
thuga
  • 12,601
  • 42
  • 52
2

First solution

You can add the following flag to the flags of your window to prevent the window from being resized by the user:

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

Here is some more information about Window Flags.


Second (ugly) experiment solution

This is kind of a dirty work-around... I'm fully aware of the fact, that this is not clean.

I just wrote this little main window that changes the cursor manually when the main window's area is left.

Note: You have to consider side effects. Maybe there is another cursor shape needed for a child widget, but this overrides the cursor for the complete application.

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

Header:

class CMainWindow :
    public QMainWindow
{
public:
    CMainWindow(QWidget* parent = nullptr);
    virtual ~CMainWindow(void);

protected:
    virtual void leaveEvent( QEvent *event );
    virtual void enterEvent( QEvent *event );
};

cpp:

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);
}
Exa
  • 4,020
  • 7
  • 43
  • 60
2

Use

setMinimumSize(QSize(width_px,height_px))

setMaximumSize(QSize(width_px,height_px))

where both methods have same size.You won't see the resize cursor & the window thus doesn't get resized/maximized.

Tushar
  • 462
  • 5
  • 12