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. how to hide checkbox of QStandardItem
Forum Updated to NodeBB v4.3 + New Features

how to hide checkbox of QStandardItem

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 3.3k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    Scarab
    wrote on last edited by
    #1

    Hello,

    is it possible to hide the checkbox of a QStandardItem if it was checkable in the past?

    I create my items with item->setCheckable(false); and there is no checkbox visible.
    Once i set item->setCheckable(true); the checkbox becomes visible... ok so far.
    The problem is when i try to set an Item to be uncheckable again the checkbox keeps being visible.

    I tried this:

    item->pq_tree_item->setCheckable(false);
    item->pq_tree_item->setTristate(false);
    item->pq_tree_item->setUserTristate(false);
    item->pq_tree_item->setEditable(false);
    

    and this:

    item->pq_tree_item->setFlags(0);
    

    but it doesn't work.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      item->pq_tree_item->setData(QVariant(),Qt::CheckStateRole);

      Looks kinda pulled out of the hat and probably should be documented better but it's quite clear if you look at the source

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      4
      • S Offline
        S Offline
        Scarab
        wrote on last edited by
        #3

        Thank you! It works like a charm.

        this is the code i am using to backup the previous check state:

        Init:

        tmp->setData( QVariant(Qt::Checked), ROLE_TREE_BACKUP_CHECKSTATE);
        tmp->setData( QVariant(),Qt::CheckStateRole);
        tmp->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
        

        Hide:

        QVariant backup = item->data(Qt::CheckStateRole);
        if( backup.isValid() && !backup.isNull() ) item->setData( backup , ROLE_TREE_BACKUP_CHECKSTATE);
        item->setData( QVariant(),Qt::CheckStateRole);
        item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
        

        Show:

        item->setData(  item->data(ROLE_TREE_BACKUP_CHECKSTATE), Qt::CheckStateRole);
        item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable );
        
        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