用于只读、可滚动、可折叠、图标列表的 Qt 小部件
我对 Qt 比较陌生,并且不太熟悉开箱即用的小部件。我有一个有点(但不是非常)复杂的小部件要创建,并且不想重新发明任何轮子。什么是最好的 QWidget 作为子类和/或 QWidget 的起点来组成我的小部件。这是我正在寻找的最终结果(对粗略的绘图表示歉意):
(来源:drmtempsoimages at site.google.com)
要点:
- 所有图标都将采用相同的大小,例如 128 x 128。忽略类别分组,它们应该全部对齐在一个漂亮的网格中。
- 小部件应该展开以填充它可以占据的所有水平和垂直区域。水平扩展/缩小可能会增加/减少每行显示的图标数量。
- 图标被分组,并且这些组应该是可折叠的。
- 如果小部件的高度超过其空间,则应出现垂直滚动条。
I'm relatively new to Qt, and am not entirely familiar with the out-of-the-box widgets. I have a somewhat (but not very) complex widget to create, and don't want to reinvent any wheels. What is the best QWidget to use as a starting point to subclass and/or QWidgets to use to compose my widget. Here is the end-result I am looking for (apologies for the crude drawing):
(source: drmtempsoimages at sites.google.com)
Key points:
- All icons will take up the same size, say 128 x 128. Ignoring the category groupings, they should all align in a nice grid.
- The widget should expand to fill all the horizontal and vertical area it can take. Expanding / shrinking horizontally may increase / decrease the number of icons shown in each row.
- Icons are grouped, and those groups should be collapsible.
- If the height of the widget exceeds its space, a vertical scrollbar should appear.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您实际上正在为 QListView/QListWidget 寻找一些更深奥的选项。
在顶层,添加
QTreeWidget
或QTreeView
将为您提供所需的层次结构,并管理滚动区域。(展开的)
QTreeXItem
的每个 Listed Item 都将是一个QListView
/QListWidget
,设置setViewMode(QListView::IconMode)
代码> 他们。编辑:
请注意,要获得上面您想要的精确外观,您可能必须使用 QListView 并使用自定义委托,自己处理绘图(除非您能找到一个完全符合您要求的主题)。不过,我在下面使用 Q*Widget 类编写了一个简短的 PyQt 解决方案,因为它们更短,并且仍然演示如何获得正确的布局。如果您使用 C++,则适用相同的 Qt 函数调用,但显然您可能有更多或更少的簿记。
You're actually looking for some of the more esoteric options for a QListView/QListWidget.
At the top level, add
QTreeWidget
orQTreeView
will give you the hierarchy you're looking for, as well as managing the scrolling area.Each Listed Item of the (expanded)
QTreeXItem
will be aQListView
/QListWidget
, settingsetViewMode(QListView::IconMode)
on them.EDIT:
Note that to get the precise look you wanted above, you'll probably have to use QListView and use a custom delegate, handling the drawing yourself (unless you can find a theme that will do exactly what you want). However, I've coded up a short PyQt solution below using the Q*Widget classes because they're shorter, and will still demonstrate how to get the right layout. If you're using C++, the same Qt function calls apply, but obviously you might have more or less bookkeeping.