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. QTreeWidgetitem how to show and keep the checkbox disabled
Forum Updated to NodeBB v4.3 + New Features

QTreeWidgetitem how to show and keep the checkbox disabled

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 3.7k 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    http://doc.qt.io/qt-4.8/qtreewidgetitem.html#setCheckState
    I have a QtreeWidgetitem and I am using

    void QTreeWidgetItem::setCheckState(int column, Qt::CheckState state)

    I want to show the checkbox and keep it disabled how can I do that

    JonBJ 1 Reply Last reply
    0
    • Q Qt Enthusiast

      http://doc.qt.io/qt-4.8/qtreewidgetitem.html#setCheckState
      I have a QtreeWidgetitem and I am using

      void QTreeWidgetItem::setCheckState(int column, Qt::CheckState state)

      I want to show the checkbox and keep it disabled how can I do that

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

      @Qt-Enthusiast

      Do you mean QTreeWidgetItem::setFlags(~Qt::ItemIsEnabled), or something based on that?

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on last edited by
        #3

        but only for one column in row of QtreeWidget

        d_treeWidget = new QTreeWidget;
        QTreeWidgetItem* rootItem = d_treeWidget->invisibleRootItem();
        QTreeWidgetItem* parentItem = rootItem;
        for (int i = 0; i < 10; i++) {
        QTreeWidgetItem* item = new QTreeWidgetItem(conf.type);
        item->setCheckState(0, Qt::Checked : Qt::Unchecked);
        item->setCheckState(1, Qt::Unchecked);
        parentItem->addChild(item);
        }

        Now I want column 1 of each row as not editable

        JonBJ 1 Reply Last reply
        0
        • Q Qt Enthusiast

          but only for one column in row of QtreeWidget

          d_treeWidget = new QTreeWidget;
          QTreeWidgetItem* rootItem = d_treeWidget->invisibleRootItem();
          QTreeWidgetItem* parentItem = rootItem;
          for (int i = 0; i < 10; i++) {
          QTreeWidgetItem* item = new QTreeWidgetItem(conf.type);
          item->setCheckState(0, Qt::Checked : Qt::Unchecked);
          item->setCheckState(1, Qt::Unchecked);
          parentItem->addChild(item);
          }

          Now I want column 1 of each row as not editable

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

          @Qt-Enthusiast
          It looks to me as though you cannot do that in a QTreeWidgetItem. See e.g. https://stackoverflow.com/questions/2801959/making-only-one-column-of-a-qtreewidgetitem-editable

          Looks like you will have to forgo using QTreeWidget and QTreeWidgetItem and go with QTreeView and QAbstractItemModel

          Also read the other replies there, showing how you can "emulate" the "not editable" via the clicked/edit delegates, e.g. https://stackoverflow.com/a/4657065/489865 looks simple.

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            Qt Enthusiast
            wrote on last edited by
            #5

            You mean no solution

            JonBJ 1 Reply Last reply
            0
            • Q Qt Enthusiast

              You mean no solution

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

              @Qt-Enthusiast
              I've just edited my solution to ask you to read what else is in that stackoverflow post....

              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