我目前正在做一个列表,我想要建立一个网格样式,并好奇我如何可以这样做。我不相信一张桌子能用,因为我想把它格式化成这样:
option option option option
option option option option
option option option option
option option option option~每行4个选项,没有进一步的信息分裂成列,其中每一行代表一个ListWidgetItem。
发布于 2016-05-19 22:37:08
你在找这样的东西:
QListWidget *listWidget = new QListWidget;
//Lays out horizontally instead of vertically
listWidget->setFlow(QListView::LeftToRight);
//Dynamically adjust contents
listWidget->setResizeMode(QListView::Adjust);
//This is an arbitrary value, but it forces the layout into a grid
listWidget->setGridSize(QSize(64, 64));
//As an alternative to using setGridSize(), set a fixed spacing in the layout:
listWidget->setSpacing(someInt);
//And the most important part:
listWidget->setViewMode(QListView::IconMode);在Qt设计器中使用这些属性。从设置QListView::IconMode开始,直到你得到你想要的行为。
发布于 2016-05-19 19:16:25
如果有静态项目数,则可以使用QGridLayout。
如果您有一个QAbstractListModel,您可以通过实现QAbstractItemView和QAbstractItemDelegate来实现您自己的视图,这就是QTableView所做的。
发布于 2016-05-20 01:01:23
您可能希望使用QTableWidget或QTreeWidget。当一行中的项目与单个项目密切相关时(即。每一行都是一项,每一列都是该项的属性),我发现使用QTreeWidget更容易。
tree = QtGui.QTreeWidget()
tree.setHeaderLabels(['Name', 'Age', 'Weight'])
item = QtGui.QTreeWidgetItem(tree, ['John Doe', '24', '150'])
item = QtGui.QTreeWidgetItem(tree, ['Jane Doe', '21', '120'])https://stackoverflow.com/questions/37331270
复制相似问题