Qt World Summit: Register Today!

Add two clickable icons to one item in treeview

  • i want to show two icons in one item line ,and the icons can be clickable ,my code is used to be one checkbox to provide one function, but now i need two.

    QVariant TreeItem::data(const QModelIndex & index, int role) const{
    QVariant output;
    if (role == Qt::CheckStateRole) {
                if (node->IsSelectable()) {
                    return Qt::CheckState::Checked;
                } else {
                    return Qt::CheckState::Unchecked;

    this code is how the checkbox show,i want to use

    else if (role == Qt::DecorationRole) {
                QPixmap Icon = QPixmap(":/.../...");

    there is only one icon.
    (icon1) (icon2)text
    is what i want
    or can i use delegate to add two pushbutton ?

  • If you are ok with two columns then the easiest way would be to just have two columns with your item, and each of them is cheackable.
    If you want to have everything in one column cell, then you need to go for a delegate.
    The delegate then can be any widget e.g. a QWidget with two QToolButtons and a QLabel on it.

Log in to reply