gpt4 book ai didi

c++ - 从 QAbstractScrollArea 派生

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:54:32 29 4
gpt4 key购买 nike

我想感受一下QT,决定写一个小的十六进制编辑器。为此,我需要一个允许滚动的小部件。经过一番研究,我发现 QTextEdit 为此目的派生自 QAbstractScrollArea。在阅读 QAbstractScrollArea 的文档时,我发现方法“setViewport()”的描述为“The QAbstractScrollArea will take ownership of the given widget.”。这不适合自行显示的小部件的上下文。它仅适用于 QScrollArea 的上下文。

在 QT 中创建带有滚动条并显示其自身内容的小部件的合适方法是什么?

最佳答案

QAbstactScrollArea 无法显示任何“自身”,文档明确指出:

QAbstractScrollArea is a low-level abstraction of a scrolling area. The area provides a central widget called the viewport, in which the contents of the area is to be scrolled (i.e, the visible parts of the contents are rendered in the viewport).

Next to the viewport is a vertical scroll bar, and below is a horizontal scroll bar. When all of the area contents fits in the viewport, each scroll bar can be either visible or hidden depending on the scroll bar's Qt::ScrollBarPolicy. When a scroll bar is hidden, the viewport expands in order to cover all available space. When a scroll bar becomes visible again, the viewport shrinks in order to make room for the scroll bar.

因为 QAbstractScrollArea 本身拥有它的视口(viewport)的所有权,所以它非常好,您不需要关心它。你可以把 QAbstractScrolArea + Viewport 的组合看作是一个单一的元素,它可以作为一个单一的元素进行操作(好吧,当然是复合元素),也可以作为一个单一的元素删除,因为获得元素的所有权意味着它会与其所有者一起被销毁。

关于c++ - 从 QAbstractScrollArea 派生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11928708/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com