QTreeView hide that "1" category?
-
I'd like to hide that gray rectangle with "1" in it.. Is it possible?
It's seen here,
http://qt-project.org/doc/qt-4.8/images/selection2.pngJust above "America".
-
You can use "setHeaderHidden(true)":http://qt-project.org/doc/qt-5.0/qtwidgets/qtreeview.html#headerHidden-prop;
@treeView->setHeaderHidden(true);@
-
When you create a custom context menu, with either the customContextMenuRequested() signal, or a redefinition of the virtual function contextMenuEvent() of your view (see "contextMenuPolicy":http://qt-project.org/doc/qt-4.8/qwidget.html#contextMenuPolicy-prop), you can get the item under the mouse with "QAbstractItemView::indexAt()":http://qt-project.org/doc/qt-4.8/qabstractitemview.html#indexAt and populate your menu accordingly.
-
-
You can either disable edit triggers for the whole view with:
@theView−>setEditTriggers(QAbstractItemView::NoEditTriggers);@or make that the set of flags returned by the model's QAbstractItemModel::flags() function doesn't include Qt::ItemIsEditable for the non-editable items or use QStandardItem::setEditable(false) if the model is a QStandardItemModel.
-
You have to call the view's "edit()":http://qt-project.org/doc/qt-4.8/qabstractitemview.html#edit function with the model index to edit (myQStandardItem->index()).
-
Another question. I've got this:
@
QModelIndex m = projectView->indexAt(p);
QString icn = m.data(Qt::DisplayRole).toString();
QMessageBox::warning(0,"!",icn);
@
But that displays name of that index (for example, someItemAtTreeView), and I want to get that item's icon instead.
I've tried Qt::DecorationRole, but I couldn't get it to return me a QIcon or QPixmap..Edit: please use @ tags around code sections; Andre
-
Could you give me an example?
bq. Why are you converting to a string, if what you are after is an image?
That was an example of what works for me, though, I don't know how to change it so I get QIcon.
If I try:QIcon icn = m.data(Qt::DecorationRole);
It is unable to convert it into QIcon. Hmmph. If I do: m.data(Qt::DecorationRole).toString() it's always an empty string.
-
If you don't set a delegate, the model is updated when the editor widget is closed, so, you can catch the change with the model's dataChanged() signal.
If you want to see both the new and old data, you need to either derive the model, to override QAbstractItemModel::setData, or install a delegate, whose QAbstractItemDelegate::setModelData() function will be called at the end of editing.