Qt窗口调整大小问题 [英] Qt window resize problem

查看:3842
本文介绍了Qt窗口调整大小问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调整大小后,重新绘制QWidget窗口时出现问题。我尝试了 update() repaint() adjustSize $ c>,但都似乎遭受同样的事情:只有部分窗口被重绘,导致窗口框架的底部和右侧不显示。

I am having a problem redrawing a QWidget window after its size has been adjusted. I have tried update(), repaint(), adjustSize(), but all seem to suffer from the same thing: only part of the window is redrawn, resulting in the window frame on the bottom and right sides to not show. The window is also not resized entirely.

为了避免这种差异,窗口位于 QMdiArea

Just in case it makes a difference, the window is in a QMdiArea.

感谢。

        //  ... some subwidget resizing and moving.
        calibrationWindowUIs[activeWindow].layoutWidget2->move(QPoint(oldXLeft, 30 + height + 21));
        calibrationWindowUIs[activeWindow].layoutWidget1->move(QPoint(oldXRight, 30 + height + 21));

        //  Set window size.
        calibrationWindows[activeWindow]->setMinimumSize(calibrationWindowUIs[activeWindow].tabWidget->geometry().width() + 40, calibrationWindowUIs[activeWindow].tabWidget->geometry().height() + 40);
        calibrationWindows[activeWindow]->update();

注意:也许我在布局上做错了什么?

Note: I'm new to Qt; perhaps I'm doing something wrong with layouts?

编辑:我可能没有提供足够的信息。好吧,说实话,我还是要深入挖掘布局和相关材料。我在这里试图做的是使用Qt设计器为了设计窗口。我做了什么也许是一个愚蠢的错误:我没有使用整个窗口的整体父布局,但黑客它与一些较小的布局,因此我必须移动和单独调整大小。请参阅Qt设计器屏幕(红色矩形是唯一的布局):。

I may have not given enough information. Alright, to be quite honest, I still have to delve deeper into layouts and related material. What I had tried to do here was to use Qt Designer in order to design the window. I've done what perhaps amounts to a stupid mistake: I didn't use an overall parent layout for the entire window, but hacked it with a couple of smaller layouts that I therefore have to move about and resize individually. See the Qt Designer screen (the red rectangles are the sole layouts): .

发生的是在右边的框架中,我播放的视频剪辑可以是各种分辨率。我想要框架的大小取决于这个分辨率,这也意味着按钮和窗口必须相应地移动/调整大小。这是窗口调整大小的地方。我敢肯定有一个更优雅的解决方案,而不是我在这里做,但我试图处理其他几个场景,因此,缺乏质量的代码。

What is happening is that in the frame to the right, I am playing a video clip that can be of various resolutions. I want the frame to resize depending on this resolution, which also means that the buttons and window have to move/resize accordingly. That is where the window resize comes in. I'm sure there is a more elegant solution than what I am doing here, but I am trying to handle several other scenarios here and hence the lack of quality of code.

结果是当我加载一个剪辑,窗口试图调整大小,但是这样做很糟糕;下面是结果:

The result is that when I load a clip, the window attempts to resize, but does so badly; the following is the result:

如果窗口被拖动,它弹出到其正确的大小;

If the window is dragged, it 'pops' into its correct size; in the meantime, however, it just looks ugly.

另外一个问题:你使用Qt Designer来设计UI吗?我发现,以编程方式,你可以实现更好的控制你的接口。我不能在设计器中做的一件事是有一个布局由主要部件父母,即相当于有以下位代码:

A couple further questions: do you use the Qt Designer to design your UIs? I found that programmatically you can achieve much better control of your interfaces. One thing which I could not do in the designer was to have a layout parented by the main widget, i.e. the equivalent of having the following bit of code:

QVBoxLayout* layout = new QVBoxLayout;
this->setLayout(layout);

布局放置在设计师总是似乎创建这个layoutWidget子窗口小部件,然后 。任何方式?

A layout placed in the designer always seems to create this 'layoutWidget' subwidget, which the layout you placed is then parented to. Any way around that?

推荐答案

我们使用设计器和代码混合创建布局,Qt布局系统可以非常不直观有时。但我可能不是在一个设计器ui文件中布置一系列完整的选项卡,我会使每个选项卡各自自己的窗口部件,然后通过代码或在设计器中通过促进自定义类来组装它们。这让你更好地分离职责,将所有选项卡的所有功能都放在一个文件中,几乎可以保证一个大型笨重的类。

We use a mix of designer and code to create layouts, the Qt layout system can be very unintuitive at times. But I would probably not layout a full series of tabs in one designer ui file, i would make each tab each own widget and then assemble them either through code or in the designer by promoting to custom classes. This gives you better separation of responsibilities, by putting all the functionality of all the tabs into one file you almost guarantee a large unwieldy class.

当窗口小部件在设计器中有子窗口小部件时,您可以通过从上下文菜单中添加布局来为其分配布局。确保没有选择任何内容,并单击要在其中创建布局的窗口小部件的背景,选择布局和所有小部件将分配给孩子的布局。

When a widget has child widgets in designer you can assign a layout to it by adding it from the context menu. Make sure nothing is selected and click on the background of the widget in which you want to create a layout, select the layout and all of the widgets children will be assigned the layout.

有助于创建布局的层次结构。看看你的第一个屏幕截图,我可能使用一个垂直布局,顶部和底部为右边的项目的间隔,一个水平布局与左右间隔的按钮栏和网格布局的所有项目在一起。没有垫片你的项目将延伸,当窗口增长。间隔将让你更好地控制调整大小时的行为。

What does help is creating hierarchies of layouts. Looking at your first screenshot, i would probably use a vertical layout with spacers on top and bottom for the items on the right, an horizontal layout with spacers left and right for the button bar and a grid layout for all the items together. Without the spacers your items will extend when the window grows. The spacers will let you control the behavior under resizing better.

这篇关于Qt窗口调整大小问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆