- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想感受一下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/
我想感受一下QT,决定写一个小的十六进制编辑器。为此,我需要一个允许滚动的小部件。经过一番研究,我发现 QTextEdit 为此目的派生自 QAbstractScrollArea。在阅读 QAbstr
我有一个用于 customContextMenuRequested 的插槽,并尝试将点转换为全局点(用于上下文菜单)。如果该类继承了 QAbstractScrollArea,则 mapToGlobal
我有一个 QTableView 和其中的一些内容。我想要像 horizontalHeader() -> setResizeMode( ResizeToContent ) 这样的行为,但它不能创建水
在派生自 QAbstractScrollArea 的自定义小部件中,我感觉无法通过 QAbstractScrollArea::viewportEvent() 处理程序接收任何键盘事件: #includ
我试图用谷歌找到这个问题的答案,但没有任何结果。我正在将应用程序从 Qt4 转换为 Qt5。该应用程序在 Qt4 中完美编译,但是当我尝试针对 Qt5 进行编译时,它给了我这个权限错误。由于此类的状态
我是一名优秀的程序员,十分优秀!