How to customize a listview in Qt - qt

I want to customize a listview in Qt, can anyone provide me some example or hints of how to do it? I am new to Qt.

You can apply stylesheet to your QListView.
Check out here for the Qt documentation of customizing QListView using stylesheets.

If you're using a standard item model or a QListWidget (or any other model that uses QStandardItem), you can set appearance properties on the items using setData.
So, The following will add a red item to a list widget:
QListWidgetItem *colorItem = new QListWidgetItem("Red");
colorItem->setData(QBrush(QColor(Qt::red)), Qt::ForegroundRole);
list.addItem(colorItem);
For a working code example and more detailed explanation, please see: http://ynonperek.com/qt-mvc-customize-items

Related

QT Arbitrary View Widget

plz click here to show the image
I want to create a set of UI like this.
I don't have source code, but I knew it's done by QT.
So I guess, overall, this is QTreeView
but how is its ChildWidget done?
All the child are different,
There are QCheckBox,
There are QLabel + QLineEdit
There are QTreeView too.
So I want to know how the child widgets are created and inserted to the QTreeView?
Thank you!
http://doc.qt.io/qt-5/modelview.html
ChildWidget are created by delegate. You can read more about delegate in Qt Model/View architecture

Qt Combo box with Check able not working

I have created a QCombobox with checkable items in Qt according to this link. But it works only when i apply QPlastiqueStyle .This style does not work in QT5. What should i do to solve this problem?
The way that I found to solve this problem was to create a custom Widget using QListWidget and QButtons and then promoting my QCombobox to the Custom widget.

is it possible to put a customize gtkwidget in a gtktreeview?

I'm learning GTK+ in this moment (after Qt) just to know what is possible with it thus Qt is for digia. Put a custom widget in a QListWidget is possible so I want to know if it is possible to do something like that using GTK+. An example of this widget could be one pixmap, one label and one button all in the same Cell and layout with a container like Gtktable.
Thanks
Yes, of course. You just need a "custom cell renderer":
http://scentric.net/tutorial/ch-treeview.html
http://gtk.php.net/manual/en/html/tutorials/tutorials.treeview.view.html

Customize List View Item in Nokia Qt App

I am writing a simple file browser app with Nokia Qt4.7 on Symbian^3 platform. I can display the directory/file list in the listview widget using QFileSystemModel. But I want to customize the list view item. And I am using QItemDelegate to do the trick overriding sizHint and paint functions. I want to display a checkbox in the end of every item (ListMode) or in the right down corder of the icon(IconMode). How can I do it?
Thanks.
I'd suggest you to reimplement QItemDelegate::paint function and use QStylePainter and use QStylePainter::drawControl to render checkbox element. Depending on the mode you can vary your painting.
You can also do this using QML . Styling rows is much easier in QML.
To be more specific your Model will still be c++ . Only the list can be in QML.

QListView how to add column?

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 ?
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.
You cannot add a column, cause list views are designed to view simple lists. You need QTable[View/Widget].
QListWidget is a single column only. Use QTreeWidget/View for multiple columns.
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).

Resources