How to disable the resize cursor

南笙酒味 提交于 2019-12-23 09:29:49

问题


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.


回答1:


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);



回答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);
}



回答3:


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.



来源:https://stackoverflow.com/questions/18521440/how-to-disable-the-resize-cursor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!