Results 1 to 3 of 3

Thread: CheckBox in treeview

  1. #1
    Join Date
    Dec 2009
    Posts
    14
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default CheckBox in treeview

    HI all,

    I just want to insert the QcheckBoxes in Qtreeview.How can I do this.

    i.e In treeview first should display the checkbox and other columns disppay the text in all rows.

    Please help me out ...


  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: CheckBox in treeview

    if you are using QStandardItemModel then use QStandardItem::setCheckable() on item you want to be checkable. Checkstate of these items you can check with QStandardItem::checkState().

    If you have your own QAbstractItemModel implementation then reimplement QAbstractItemModel::flags() method and return Qt::ItemIsUserCheckable for indexes that you want to be checkable. Checkstate is stored under Qt::CheckStateRole.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. #3
    Join Date
    Dec 2009
    Posts
    14
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: CheckBox in treeview

    This is how I am doing currently... But instead of checkbox its displaing the combobox with true and false value .Where I am wrong exactly ? .....





    void addModel(QAbstractItemModel *model, const QCheckBox *check,const QString &name,
    const QString &id, const QString &status )
    {
    model->insertRow(0);

    model->setData(model->index(0, 0), check);
    model->setData(model->index(0, 1), name);
    model->setData(model->index(0, 2), id);
    model->setData(model->index(0, 3), status);
    }

    QAbstractItemModel *createMailModel(QObject *parent)
    {
    QStandardItemModel *model = new QStandardItemModel(0, 4, parent);
    QCheckBox *check = new QCheckBox("");


    model->isWidgetType();
    model->setHeaderData(0, Qt::Horizontal, Qt::CheckStateRole );
    model->setHeaderData(1, Qt::Horizontal, QObject::tr("Name"));
    model->setHeaderData(2, Qt::Horizontal, QObject::tr("Dept"));
    model->setHeaderData(3, Qt::Horizontal, QObject::tr("Section"));

    addModel(model, check,"Ansar", "Prodution","Testing");
    return model;

    }

Similar Threads

  1. boolean field checkbox QTableView
    By skuda in forum Qt Programming
    Replies: 4
    Last Post: 8th November 2010, 13:48
  2. Replies: 2
    Last Post: 27th September 2009, 21:36
  3. How can I center a checkbox in a treeview?
    By 3str in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2009, 06:47
  4. QTreeView: How to center a checkbox in a cell
    By chezifresh in forum Qt Programming
    Replies: 3
    Last Post: 19th December 2008, 12:11
  5. Need some help re-painting a checkbox
    By JimDaniel in forum Qt Programming
    Replies: 2
    Last Post: 25th January 2008, 16:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.