简体   繁体   English

为包含多个 QQuickPaintedItems 的 QQuickView 实现滚动

[英]Implement Scrolling for QQuickView containing multiple QQuickPaintedItems

So recently I started a project where I want to display a graph showing relations between different datasets.所以最近我开始了一个项目,我想在其中显示一个图表,显示不同数据集之间的关系。

The graph consists of Edges and Nodes, while both of these classes inherit QQuickPaintedItem and override the paint(QPainter* painter) method.该图由边和节点组成,而这两个类都继承了 QQuickPaintedItem 并覆盖了paint(QPainter*painter) 方法。 I have another class which stores all Nodes and Edges in two QLists.我有另一个 class 将所有节点和边存储在两个 QList 中。 When I want to display the Graph, the paint method for every Node and Edge is called and is being painted into a QQuickView.当我想显示图表时,每个节点和边缘的绘制方法都会被调用并被绘制到 QQuickView 中。 I do this by setting a Qml File for the QQuickView (important: The loaded qml File has nothing to do with the actual Graph, everything is painted with the paint-method from QQuickPaintedItem and i haven't exposed anything related to the Graph to Qml. The Qml File is being used to display some controls for the graph) and getting the content item (QQuickItem* from method contentItem()) of the QQuickView and setting it as a parent for every Node and Edge. I do this by setting a Qml File for the QQuickView (important: The loaded qml File has nothing to do with the actual Graph, everything is painted with the paint-method from QQuickPaintedItem and i haven't exposed anything related to the Graph to Qml . Qml 文件用于显示图表的一些控件)并获取 QQuickView 的内容项(QQuickItem* from method contentItem())并将其设置为每个节点和边缘的父项。 All of this works fine for me.所有这些对我来说都很好。

Now to my problem: Some of the graphs I wanna display are bigger than my actual view i want to display them in, so to solve this i want to implement horizontal and vertical Scrolling for my View.现在我的问题是:我想要显示的一些图表比我想要显示它们的实际视图大,所以为了解决这个问题,我想为我的视图实现水平和垂直滚动。 However I haven't found anything that seems to solve my problem due to the fact that i can't use predefined Qml-Layouts like ListView aso.但是,由于我不能使用像 ListView 这样的预定义 Qml 布局,所以我没有找到任何似乎可以解决我的问题的方法。 for my Graph.对于我的图表。

Does anyone have an idea how I could implement Scrolling?有谁知道我如何实现滚动? Is there a way to implement this for my QQuickView or is there are way to expose my two Lists of Nodes and Edges to Qml and implement Scrolling in there?有没有办法为我的 QQuickView 实现这一点,或者有没有办法将我的两个节点和边缘列表公开给 Qml 并在那里实现滚动?

(If you need some code, feel free to ask. I don't think it makes sense to share some code right now since I'm searching for an idea what to do about this topic in the first place). (如果您需要一些代码,请随时提出。我认为现在分享一些代码是没有意义的,因为我首先正在寻找如何处理这个主题的想法)。

Thank you!谢谢!

If you don't mind rendering everything, what you need is Flickable .如果您不介意渲染所有内容,那么您需要的是Flickable

Set the viewable width and height of your Flickable (explicitely, with anchors, or with layouts) and nest your custom item in it and set the contentWidth and contentHeight of the flickable depending on the total size or your custom item.设置 Flickable 的可视宽度和高度(明确地,使用锚点或布局)并将您的自定义项嵌套在其中,并根据总大小或自定义项设置 flickable 的contentWidthcontentHeight

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM