Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. When my QListView get the focus and it's all items activate. but , i don't want it.

When my QListView get the focus and it's all items activate. but , i don't want it.

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • joeQJ Offline
    joeQJ Offline
    joeQ
    wrote on last edited by joeQ
    #1

    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);
    }
    

    Just do it!

    1 Reply Last reply
    0
    • joeQJ Offline
      joeQJ Offline
      joeQ
      wrote on last edited by joeQ
      #2

      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 add QStyle::State_HasFocus and QStyle::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.

      Just do it!

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved