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. QStandardItem, store property
Forum Update on Monday, May 27th 2025

QStandardItem, store property

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 510 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    I am using QStandardItem to show a text cell in a QTableView, the text in the cell is so long, its a full path, so I've cut down to just the file name. I want to store the original as a hidden property with the item, can this be done?

    I can't see any property or setProperty methods on this class.

    [Edit] Sorted, the original data is now stored in the tooltip.

    Kind Regards,
    Sy

    JonBJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      I am using QStandardItem to show a text cell in a QTableView, the text in the cell is so long, its a full path, so I've cut down to just the file name. I want to store the original as a hidden property with the item, can this be done?

      I can't see any property or setProperty methods on this class.

      [Edit] Sorted, the original data is now stored in the tooltip.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @SPlatten
      QStandardItem does not have an arbitrary "property". But it does have setData()/data() with an arbitrary role to store/retrieve whatever you want in the model.

      EDIT Your

      [Edit] Sorted, the original data is now stored in the tooltip.

      A bit naughty, to use the tooltip for something which you actually mean to retrieve.

      EDIT2
      From your latest I see you have come to same conclusion!

      SPlattenS 2 Replies Last reply
      2
      • JonBJ JonB

        @SPlatten
        QStandardItem does not have an arbitrary "property". But it does have setData()/data() with an arbitrary role to store/retrieve whatever you want in the model.

        EDIT Your

        [Edit] Sorted, the original data is now stored in the tooltip.

        A bit naughty, to use the tooltip for something which you actually mean to retrieve.

        EDIT2
        From your latest I see you have come to same conclusion!

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #3

        @JonB , Thats better then my tool tip solution, thank you.

        Kind Regards,
        Sy

        1 Reply Last reply
        1
        • JonBJ JonB

          @SPlatten
          QStandardItem does not have an arbitrary "property". But it does have setData()/data() with an arbitrary role to store/retrieve whatever you want in the model.

          EDIT Your

          [Edit] Sorted, the original data is now stored in the tooltip.

          A bit naughty, to use the tooltip for something which you actually mean to retrieve.

          EDIT2
          From your latest I see you have come to same conclusion!

          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by SPlatten
          #4

          @JonB , When I create the item:

          QString strOriginal, strValue(it.value().toString());
          if ( f == DataSets::mcuint16Filename ) {
              int intLDelmtr = strValue.lastIndexOf("/");
              if ( intLDelmtr >= 0 ) {
                  strOriginal = strValue;
                  strValue = strValue.mid(intLDelmtr + 1);
              }
          }
          QStandardItem* psItem(new QStandardItem(strValue));
          psItem->setFlags(psItem->flags() & ~Qt::ItemIsEditable);
          if ( strOriginal.isEmpty() != true ) {
              psItem->setData(strOriginal);
          }
          lstRow.append(psItem);
          

          In the lambda slot that handles the double click:

          QModelIndex objIndex(objColumn.at(c));
          QString strItem(objIndex.data().toString());
          

          c is an integer between 0 and number of columns, the above always gives the text assigned to the column which in the case of the file name (column 0) is just the file name without the path.

          How do I get access to the QStandardItem that was appended to the row?

          [Edit] Done:

          QStandardItem* pItem(this->mpsiModel->itemFromIndex(objIndex));
          

          Kind Regards,
          Sy

          1 Reply Last reply
          0

          • Login

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