When my QListView get the focus and it's all items activate. but , i don't want it.
Solved
General and Desktop
-
In my project, i used the customize model and delegate. but, when i run my demo. I found the if the listview get the focus and then, it's all items become activate. oh, i don't know the reason.
// ListView.cpp #include "listview.h" #include "styleditemdelegate.h" #include "itemmodel.h" ListView:: ListView(QWidget *parent): QListView(parent) { StyledItemDelegate *pDelegate = new StyledItemDelegate(this); setItemDelegate(pDelegate); ItemModel *pItemModel = new ItemModel(this); setModel(pItemModel); setViewMode(QListView::IconMode); setResizeMode(QListView::Adjust); setMovement(QListView::Free); setDragEnabled(false); setSpacing(10); //setStyleSheet("QListView::item:selected{border:1px solid #555555}"); //setStyleSheet("QListView{outline:0px;}"); //setEditTriggers(QAbstractItemView::NoEditTriggers); setSelectionRectVisible( true ); setSelectionBehavior( QAbstractItemView::SelectItems ); setSelectionMode( QAbstractItemView::ExtendedSelection ); //setMouseTracking(false); } ListView::~ListView() { } void ListView::AppendItems(QStringList ltImgFiles) { foreach(QString file, ltImgFiles){ AppendItem(file); } } void ListView::AppendItem(QString qsImgFileName) { ItemModel *pItemModel = (ItemModel *)model(); QStandardItem *pItem = new QStandardItem; pItem->setSizeHint( QSize(100,120) ); pItem->setData( qsImgFileName, Qt::UserRole ); pItem->setData( qsImgFileName, Qt::ToolTipRole ); pItem->setFlags( Qt::ItemIsSelectable ); //pItem->setFlags(Qt::ItemIsUserCheckable); //pItem->setText( QString::number(pItemModel->rowCount()+1) ); //pItem->setTextAlignment( Qt::AlignBottom | Qt::AlignHCenter ); pItemModel->appendRow(pItem); }
-
I am sorry, I get it. I misunderstand the item activate state.
QStyle::State_Active Indicates that the widget is active.
when the listview get the focus, and it's all items state become active.
if you use the mouse over the item, and the item state will add
QStyle::State_MouseOver
if you use the mouse click the item, and the item state will addQStyle::State_HasFocus
andQStyle::State_Selected
so, From these state, we can know what items selected.
OK, i get it. if some one has problem about it, can tell me.