Qt 中具有固定大小的不可调整大小的 QDialog?
我有一个 Qt 对话框应用程序。 现在我不希望该对话框可调整大小。 我不知道如何实现这一目标。 我尝试了很多方法,但当对话框启动时,仍然可以调整该对话框的大小。
我应该设置什么属性来禁用对话框/小部件调整大小。
我也尝试过,
setSizePolicy(QSizePolicy::Fixed);
但我收到一条错误消息,
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'
请帮我解决这个问题。
I have a Qt dialog application. Now I dont want that dialog to be resizeable. I am not sure how to achieve this. I tried a bunch of things but still when the dialog launches this dialog can be resized.
What is the property that i should set to disable the dialog/Widget resize.
I also tried
setSizePolicy(QSizePolicy::Fixed);
But i get an error saying..
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'
Kindly help me out with this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
您收到的编译错误是因为您尝试将
QSizePolicy::Policy
传递给setSizePolicy(QSizePolicy)
,但没有从QSizePolicy::Policy< 进行隐式转换。 /code> (这是一个维度的策略)到
QSizePolicy
(这是一个包含每个维度(高度、宽度)一个Policy
等内容的类)。 不过,QSizePolicy
无论如何都不适用于顶级小部件(窗口)。setFixedSize()
仅在您提前知道对话框的大小时才有效(通常您不会,因为更改字体大小和语言)。 您可以这样做,但最好使用
它让布局确定对话框的大小,但不允许调整大小,我认为这就是您所要求的。
The compile error you get is because you try to pass a
QSizePolicy::Policy
tosetSizePolicy(QSizePolicy)
, but there's no implicit conversion fromQSizePolicy::Policy
(which is the policy for one dimension) toQSizePolicy
(which is a class containing, among other things, onePolicy
per dimension (height, width)).QSizePolicy
doesn't work on top-level widgets (windows) anyway, though.setFixedSize()
only works if you know the size of the dialog in advance (and usually you don't, what with changing font sizes and languages). You can dobut it's much better to use
That lets the layout determine the size of the dialog, but doesn't allow resizing, which I assume is what you were asking for.
我不知道你是否已经尝试过,但是
QWidget::setFixedSize
应该做你想做的I don't know if you already tried it, but
QWidget::setFixedSize
should do what you want您需要更改对话框的windowFlags并将其设置为Qt::MSWindowsFixedSizeDialogHint。
这只适用于Windows。
有关更多信息,请参阅此示例:
http://doc.qt.digia.com/4.5/widgets-windowflags。 html
You need to change the windowFlags of the dialog and set it to Qt::MSWindowsFixedSizeDialogHint.
This only works in windows.
For more information please see this example:
http://doc.qt.digia.com/4.5/widgets-windowflags.html
在 QT Creator 的 UI 编辑器中,单击属性窗口中的顶部对象,然后滚动到布局部分的底部。 您应该看到layoutSizeConstraint 属性。
将
layoutSizeConstraint
设置为SetFixedSize
。On QT Creator, in the UI editor, click on the top object in the properties window, then scroll at the bottom in the Layout part. You should see the layoutSizeConstraint property.
Set the
layoutSizeConstraint
toSetFixedSize
.如果您使用 QtCreator(当然是),您可以将 HorizontalsizePolicy 属性设置为固定,并将垂直策略也设置为固定。 然后你可以将maximumSize设置为你想要的尺寸。 窗口不会再次最大化。
If you use QtCreator (of course you are) you can set the property HorizontalsizePolicy to fixed and Vertical Policy also to Fixed. Then you can set the maximumSize to the dimensions you want. The window will not maximise again.
在代码中你可以做这样的事情,
在QtCreator中执行如下操作,
In code you can do something like this,
In QtCreator do as follows,
从 Qt 文档来看,
setSizePolicy()
方法要么采用零个参数,要么采用两个参数,但不能是一个参数。 这就是您收到此编译错误的原因。 根据我的实验,如果不设置固定大小。 这个方法没有什么用。 窗口的大小仍然可以调整。From the Qt documentation,
setSizePolicy()
method either takes zero argument or two arguments but cannot be one argument. That's why you get this compilation error. From my experiment, if you don't set the fixed size. This method has no use. The window can still be resizable.更简单的方法是将最大大小设置为 0。
An easier way is to set the maxium size to 0.
如果您正在 QML 中设计 UI 并使用 QDeclarativeView 启动,请尝试以下代码。
这里QmlApplicationViewer是从QDeclarativeView派生的。
In case you are designing UI in QML and launching using QDeclarativeView, try the below code.
Here QmlApplicationViewer is derived from QDeclarativeView.