checkbox and itemdelegate in a tableview

后端 未结 6 1011
攒了一身酷
攒了一身酷 2020-12-31 22:32

I\'m doing an implementation of a CheckBox that inherits from QitemDelegate, to put it into a QTableView.

the problem is that I get when inserted flush left and I ne

6条回答
  •  醉酒成梦
    2020-12-31 22:47

    that's what I did to center-allign the editor control:

    QWidget *checkBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
        QCheckBox *editor = new QCheckBox(parent);
        editor->setTristate(allowTriState); //my class' variable
        // this does the trick :)
        editor->setStyleSheet("QCheckBox {margin-left: 43%; margin-right: 57%;}"); 
        // this should do it better
        // editor->setStyleSheet("QCheckBox {margin-left: auto; margin-right: auto;}");
        // but in my case the checkbox is slightly to the left of original
        return editor;
    }
    

提交回复
热议问题