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] Checkbox added to QStandardItem with setCheckable(false) ?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Checkbox added to QStandardItem with setCheckable(false) ?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 4.9k 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.
  • R Offline
    R Offline
    richelbilderbeek
    wrote on last edited by
    #1

    Dear fellow programmers,

    I worked on a simple QTableView example that uses custom data (using a derived class of QStandardItemModel). The (downsized) core is to implement a QStandardItemModel that displays a custom data type with a std::vectorstd::string.

    [code]
    struct MyModel : public QStandardItemModel
    {
    MyModel(/* /)
    {
    for (int i=0; i!=/
    /; ++i)
    {
    QList<QStandardItem
    > items;
    //Add text
    {
    QStandardItem * const item = new QStandardItem;
    item->setCheckable(false); //NO CHECKBOX!
    items.push_back(item);
    }
    //Only have one column for now
    assert(this->columnCount() == items.size());
    this->appendRow(items);
    }
    }
    }
    [/code]

    Although I explicity setCheckable to false, when I view my application, it does show checkboxes.

    What did I miss?

    Full code (including screenshot and full Qt Project download) at http://www.richelbilderbeek.nl/CppQTableViewExample5.htm

    Thanks, Bilderbikkel

    1 Reply Last reply
    0
    • R Offline
      R Offline
      richelbilderbeek
      wrote on last edited by
      #2

      Solved! The cause was not in the code posted, but in MyModel::data:

      [code]
      struct MyModel : public QStandardItemModel
      {
      ///Implement virtual member function
      QVariant data(const QModelIndex &index, int role) const
      {
      //Removing this line will cause checkboxes to appear
      if (role != Qt::EditRole && role != Qt::DisplayRole) return QVariant();

      //Work on data
      

      }
      };
      [/code]

      Good luck with this answer B-)

      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