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. [SOLVED]Checked and disabled
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Checked and disabled

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 3.0k 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.
  • T Offline
    T Offline
    toho71
    wrote on last edited by
    #1

    I got a tableview and in one of the columns there are a chk box.
    When the user "checks " this box I would like to set the chkbox ->setEnabled(false).
    I have tried but no solution for the moment.

    If anyone know how or just give a little hint I would be happy.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      If you gave us a little more details we would be happy, too :)

      Right now, as I do not know anything about your code/ your attempts, I'll just give a vague hint that might help: use QCheckBox::stateChanged() signal. Connect a slot to it and put your disabling code there.

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        Are you looking for QAbstractItemModel::flags()? Especially the enabled flag?

        1 Reply Last reply
        0
        • T Offline
          T Offline
          toho71
          wrote on last edited by
          #4

          Here is some code
          I Save the rows in a QVector and when the user peresses a button this code executes
          @
          for (int i = 0; i < selectedToAck.size(); ++i)
          {
          row = selectedToAck.at(i); //Rownumber
          index = model->indexFromItem(model->item(row,4));//Get the columndatat
          model->setData(index,"No",Qt::DisplayRole); //Changes the text in the column

          //Changes the color of the items
          for (int j = 0;j < colCount;j++)
          {
          model->setData(model->index(index.row(),j), grey, Qt::ForegroundRole);

          //Here is the place where I want to set the item enabled == false
          if (j == colCount-1)
          {
          model->index(index.row(),j).setEnabled(false);
          }
          }//for j@

          This is not all of the code in the method but it's the part that belongs to my problem

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            What model do you use?
            It depends on the model how you can control the enabled flag. If you use [[doc:QStandardItemModel]], you can use QStandardItem::setFlags(), but if you use another type of model, it depends.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              toho71
              wrote on last edited by
              #6

              I use QStandardItem model

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                So, does using setFlags() work for you?

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  toho71
                  wrote on last edited by
                  #8

                  Solution in a simple way

                  @QStandardItem *itm = model->itemFromIndex(model->index(index.row(),j));
                  itm->setEnabled(false);@

                  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