QListView how to add column?
Asked Answered
E

4

21

How can I add columns to QListView control. Found a method addColumn while seardhing, but in my Qt Creator 1.2.1 based on Qt 4.5.2(32 bit) QListView doesn't have such method at all !!!

So how would I add columns ?

Say I have 3 columns then what is the code to add a row ?

Excursive answered 15/4, 2010 at 11:21 Comment(0)
D
14

You can use QTableView for this purpose. But if you need QListView look & feel, you can use QTableView borderless using Qt Stylesheet. Also you may want to add an icon. You can add icons to your QTableView by setting icon data to Qt::DecorationRole.

Dodger answered 25/11, 2010 at 14:40 Comment(0)
W
8

You cannot add a column, cause list views are designed to view simple lists. You need QTable[View/Widget].

Wilfordwilfred answered 15/4, 2010 at 12:2 Comment(0)
O
6

QListWidget is a single column only. Use QTreeWidget/View for multiple columns.

Occupy answered 23/6, 2015 at 6:15 Comment(0)
O
1

As the start point you could watch how works QTableView class here: http://qt.nokia.com/doc/4.2/sql-tablemodel.html and do the similar things with QListView. So, you can't just emit addColumn() for QListView class, first you need to create model and then do listView->setModel(model).

Officialism answered 15/4, 2010 at 12:6 Comment(1)
It will not work due to QListView realization. It accept multicolumn models, but show only one of these. When you connect such model, you should set setModelColumn(index) to specify one the list will show.Wilfordwilfred

© 2022 - 2024 — McMap. All rights reserved.