How to Fully Disable Resizing a Window Including the Resize Icon When the Mouse Hovers the Border

how can I fully disable resizing a window including the resize icon when the mouse hovers the border?

Qt has a windowFlag called Qt::MSWindowsFixedSizeDialogHint for that. Depending on what you exactly want, you want to combine this flag with Qt::Widget, Qt::Window or Qt::Dialog.

void MyDialog::MyDialog()
{
setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);

...
}

How to disable resize pointer in a QWidget? [duplicate]

Qt::MSWindowsFixedSizeDialogHint

Gives the window a thin dialog border on Windows. This style is traditionally used for fixed-size dialogs.

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Form(object):
def setupUi(self, nCode_analysis_set_up):
nCode_analysis_set_up.setFixedSize(350, 200)

if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
nCode_analysis_set_up = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(nCode_analysis_set_up)

nCode_analysis_set_up.setWindowFlags(nCode_analysis_set_up.windowFlags()
| QtCore.Qt.MSWindowsFixedSizeDialogHint
)

nCode_analysis_set_up.show()
sys.exit(app.exec_())

Is there a way to enable/disable window resizing at runtime in qt c++

Calling setFixedSize() is essentially calling both setMaximumSize() and setMinimumSize(). Therefore, to undo the effect, you can set the minimum size to 0, and maximum size to QWIDGETSIZE_MAX (2^24 - 1, or 16777215).

#include "mainwindow.h"

#include <QCheckBox>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
auto checkbox = new QCheckBox{tr("Resizable")};
checkbox->setChecked(true);
this->setCentralWidget(checkbox);

this->resize(200, 100);
connect(checkbox, &QCheckBox::stateChanged, this, [this](int state)
{
if (state != Qt::Checked)
this->setFixedSize(this->width(), this->height());
else
{
this->setMinimumSize(0, 0);
this->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
}
});
}

MainWindow::~MainWindow()
{
}

Disable QSizeGrip for QMainWindow [duplicate]

Windows seems to be a bit adamant about being the cross-platform friendly OS. The way to fix the problem is by adding a window flag. The code:

goes into your main.cpp:

// Disable resize arrow.
#if defined(Q_OS_WIN)
w.setWindowFlags(w.windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
#endif

Complete code:

#if defined(Q_OS_WIN)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QApplication a(argc, argv);
Compressor w;

// Disable resize arrow.
#if defined(Q_OS_WIN)
w.setWindowFlags(w.windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
#endif

w.setFixedSize(QSize(360,450));
w.setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
w.setGeometry(
QStyle::alignedRect(
Qt::LeftToRight,
Qt::AlignCenter,
w.size(),
a.desktop()->availableGeometry()
)
);
w.show();

OR

You can also add it to your MainWindow.cpp file as:

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

See http://doc.qt.io/qt-5/qt.html#WindowType-enum for more.

Qt QWidget disable re sizing more than minimum size needed [duplicate]

Try this in your main window:

this->layout()->setSizeConstraint(QLayout::SetFixedSize);

This is the result i got:

enter image description here

Resizing main window: how do I know which side is used for resizing?

I don't know if there is an elegant solution because different operating systems handle borders differently.

My suggestion is

  • to compute the difference between the current and previous window size each time it is drawn
  • Get the mouse cursor's position.
  • If the window X changes, the border used is probably the left or right -- whichever the mouse cursor is closest to. If the Y changes, probably the top or bottom border the cursor is closest to.
  • If both change, the corner the mouse cursor is closest to is probably it.

A few corner cases may come up. For example, a window can be resized on some systems using the keyboard. It can potentially also be resized programatically, like when the user changes to a resolution too low to contain your window. These things can be handled in most cases by detecting of the mouse button is clicked while the resize is taking place.

Also, it is possible to resize just the width or height from the corner. In these cases, you may have to choose a threshold for mouse distance from corner that would decide whether it is actually at a corner.

Window Geometry picture from Nokia

Qt Linux/XP difference - making window unresizable by user

There are several questions about related problems on Stackoverflow already:

  • Non-resizeable QDialog with fixed size in Qt?
  • setFixedSize doesn't work as expected
  • In Qt C++, how can I fully disable resizing a window including the resize icon when the mouse hovers the border?

The solution might be to use the Qt::MSWindowsFixedSizeDialogHint QWindowFlag, or to set the parent layout (the main widget layout) to non-resizable, as suggested in this answer:

window->layout()->setSizeConstraint( QLayout::SetFixedSize );

Keep an HTA window from resizing

Add this below:

<HTA:APPLICATION
MAXIMIZEBUTTON="NO"
SCROLL="NO"
BORDER="DIALOG"
/>

Note - If you want to allow user to scroll, change SCROLL string from NO to YES



Related Topics



Leave a reply



Submit