Solved How to remove list view item dot line ? i had searched and try some ways but not work.
-
In the list view, when the item get the focus or selected, and there is one dot line over the item.
i used the delegate to repainter the item. like the image:
but the dot line ...
I also know many people had the question. and i also try some ways, such:
setStyleSheet("QListView::item:focus{border:none;}"); setStyleSheet("QListView::item:focus{outline:none;}"); setStyleSheet("QListView::item:focus{outline:0px;}"); setStyleSheet("QListView::item{border:none;}"); setStyleSheet("QListView::item{outline:none;}"); setStyleSheet("QListView::item{outline:0px;}");
They are all failed! I want to cry...
I also saw the topic qt fourm topic
-
Haha, I solved my problem. O(∩_∩)O~~, Just easy. Use the delegate and then.
void StyledItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { /** some code at here */ qDebug() << option.showDecorationSelected; // --------------------false pen = painter->pen(); if( option.state & QStyle::State_Selected ) { pen.setColor( QColor(65,105,255) ); } else { pen.setColor( QColor(211,211,211) ); } /** some code at here */ /** QStyledItemDelegate::paint(painter, option, index); */ // **don't need this line code.** }
In the
StyledItemDelegate::paint
function, we don't add this line codeQStyledItemDelegate::paint(painter, option, index);
OK, If some one also has the problem, can tell me.
-
Hi,
Have you tried to set option.showDecorationSelected=false via QStyledItemDelegate::initStyleOption(). According to the docu of QStyledItemDelegate::paint this seems to be an option for this kind of changes.
-Michael. -
I saw the Qt manual. Found
QStyleOptionViewItem::showDecorationSelected
bool QStyleOptionViewItem::showDecorationSelected
This variable holds whether the decoration should be highlighted on selected items.
If this option is true, the branch and any decorations on selected items should be highlighted, indicating that the item is selected; otherwise, no highlighting is required. The default value is false.And, I qDebug the value in my code; It is false. It doesn't solve my problem.
void StyledItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { /** some code at here */ qDebug() << option.showDecorationSelected; // --------------------false pen = painter->pen(); if( option.state & QStyle::State_Selected ) { pen.setColor( QColor(65,105,255) ); } else { pen.setColor( QColor(211,211,211) ); } /** some code at here */ QStyledItemDelegate::paint(painter, option, index); }
-
Haha, I solved my problem. O(∩_∩)O~~, Just easy. Use the delegate and then.
void StyledItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { /** some code at here */ qDebug() << option.showDecorationSelected; // --------------------false pen = painter->pen(); if( option.state & QStyle::State_Selected ) { pen.setColor( QColor(65,105,255) ); } else { pen.setColor( QColor(211,211,211) ); } /** some code at here */ /** QStyledItemDelegate::paint(painter, option, index); */ // **don't need this line code.** }
In the
StyledItemDelegate::paint
function, we don't add this line codeQStyledItemDelegate::paint(painter, option, index);
OK, If some one also has the problem, can tell me.
-
@m.sue Think you very much. I get it.