Emphasizing "current item" in subclass of QAbstractItemView
By default, there is some barely visible dotted rectangle around the
QItemSelectionModel::currentIndex (). Has anyone suggestions how to change
this efficiently. (i.e. I think adjusting the model data with setData() and
Qt::FontRole or Qt::BackgroundRole or something similar isn't the right way
to do this.)
So has anyone any other suggestions?
Kind regards,
Davor
Re: Emphasizing "current item" in subclass of QAbstractItemView
set your own delegate and reimplement its paint method. There simply remove QStyle::State_Selected from the QStyleOptionViewItem and pass all argument the the base class.
(There are some threads about that topic in the forum)
Re: Emphasizing "current item" in subclass of QAbstractItemView
Thanks Lykurg.
I'll try your suggestion next week. I also couldn't find any relevant post about the "current" item. I did find posts about “selected” item(s), but that's not the issue here.
Re: Emphasizing "current item" in subclass of QAbstractItemView
Damn, everytime I came into that trouble with QStyle::State_HasFocus and QStyle::State_Selected....
The dotted line is the result of one or these two states. So in the "selected items threads" you will find how to remove these flag inside the paint event. And there is the connection to your "current item" problem ;)
Re: Emphasizing "current item" in subclass of QAbstractItemView
I hope I remember next time:p
Code:
#include <QtGui>
{
public:
{}
virtual void paint
(QPainter* painter,
const QStyleOptionViewItem
& option,
const QModelIndex
& index
) const {
opt = const_cast<QStyleOptionViewItem&>(option);
opt.
state &= ~
QStyle::State_HasFocus;
}
};
int main(int argc, char** argv)
{
MyDelegate delegate(&view);
view.setItemDelegate(&delegate);
model.setRowCount(10);
model.setColumnCount(10);
for (int row = 0; row < model.rowCount(); ++row)
{
for (int column = 0; column < model.columnCount(); ++column)
{
model.setItem(row, column, item);
}
}
view.setModel(&model);
view.show();
return app.exec();
}
Re: Emphasizing "current item" in subclass of QAbstractItemView
Ehm.. and change is not remove! But once you have removed it, you can paint your own emphasized border. If you want to change it directly, you have to subclass QStyle and write your own routine there. But that is more complex (QProxyStyle).