Oversized QDialog with fixed size in Qt?

I have a Qt dialog application. Now I do not want this dialogue to be changed. I am not sure how to achieve this. I tried a bunch of things, but still, when a dialog launches this dialog, you can resize it.

What is the property that I have to set to disable dialog / widget changes.

I also tried

setSizePolicy(QSizePolicy::Fixed); 

But I get an error message.

 source \ nimcac_settingsMain.cpp (36): error C2248:
 ** 'QSizePolicy :: QSizePolicy': cannot access private member declared in class 'QSizePolicy' **
         p: \ ThirdPartyExports \ Qt \ export \ 4.3 \ 4.3.1f14 \ include \ QtGui \ ../../ src \ gui \
 kernel \ qsizepolicy.h (177): see declaration of 'QSizePolicy :: QSizePolicy'
         p: \ ThirdPartyExports \ Qt \ export \ 4.3 \ 4.3.1f14 \ include \ QtGui \ ../../ src \ gui \
 kernel \ qsizepolicy.h (34): see declaration of 'QSizePolicy'

Please help me with this.

+61
qt qdialog
Mar 30 '09 at 6:42
source share
9 answers

I do not know, you have already tried, but QWidget::setFixedSize should do what you want

+48
Mar 30 '09 at 14:37
source share

The compilation error is that you are trying to pass QSizePolicy::Policy to setSizePolicy(QSizePolicy) , but there is no implicit conversion from QSizePolicy::Policy (which is the policy for one dimension) to QSizePolicy (which is a class containing, among other things, one Policy per size (height, width)). However, QSizePolicy does not work on top-level widgets (windows).

setFixedSize() only works if you know the size of the dialog box in advance (and usually you don’t do this, which changes the font size and languages). You can do

 window()->setFixedSize( window()->sizeHint() ); 

but much better to use

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

This allows the layout to determine the size of the dialog box, but does not allow you to change the size that I assume is what you are asking for.

+90
Jul 20 '09 at 5:42
source share
 this->setFixedSize(this->width(),this->height()); 
+21
Oct. 14 '09 at 3:18
source share

You need to change the windowFlags of the dialog box and set it to Qt :: MSWindowsFixedSizeDialogHint.

This only works in windows .

For more information, see this example: http://doc.qt.digia.com/4.5/widgets-windowflags.html

+7
Mar 30 '09 at 7:33
source share

If you use QtCreator (of course you are), you can set the HorizontalsizePolicy property to fixed, and the vertical policy to Fixed. Then you can set the maximum size to the desired size. The window will no longer expand.

+5
Nov 02
source share

In code, you can do something like this,

 Dialog->resize(581, 292); QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); sizePolicy.setHeightForWidth(WaterLevelEditorDialog->sizePolicy().hasHeightForWidth()); Dialog->setSizePolicy(sizePolicy); Dialog->setMinimumSize(QSize(581, 292)); Dialog->setMaximumSize(QSize(581, 292)); Dialog->setSizeGripEnabled(false); 

In QtCreator, do the following:

  • Select a dialog widget
  • Find the dialog widget in the object window
  • In the object window, right-click the dialog object to open the menu
  • Choose "Size Limits" β†’ "Set Maximum Size" in the menu
  • Right-click on the dialog object to open the menu.
  • Choose "Size Limit" β†’ "Set Minimum Size"
  • In the properties window,
    • provide "policy size" β†’ "Horizontal policy" has the value "fixed"
    • provide "policy size" β†’ "Vertical policy" has the value "fixed"
    • ensure that the value of "sizeGripEnabled" is not checked
+2
Feb 01
source share

In QT Creator, in the user interface editor, click on the top object in the properties window, and then scroll to the bottom of the layout. You should see the layoutSizeConstraint property.

Set layoutSizeConstraint to SetFixedSize .

+2
Jun 06 '14 at 12:44 on
source share

From the Qt documentation, the setSizePolicy() method either takes a null argument, or two arguments, but cannot be a single argument. This is why you get this compilation error. From my experiment, unless you set a fixed size. This method does not make sense. The window can still be resized.

+1
Mar 08 2018-12-12T00:
source share

If you are developing a user interface in QML and starting using QDeclarativeView, try the code below.

 QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create()); . . . //To make the window non-resizable viewer->setFixedSize(viewer->width(),viewer->height()); 

Here QmlApplicationViewer is derived from QDeclarativeView.

0
Oct 19
source share



All Articles