Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    1
    2
    900
    Loading More Posts
    • 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.
    • joeQ
      joeQ last edited by joeQ

      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 Reply Quote 0
      • joeQ
        joeQ last edited by joeQ

        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 Reply Quote 1
        • First post
          Last post