Qt QTableView - Alignment of checkbox when using IsUserCheckable

前端 未结 6 2553
余生分开走
余生分开走 2021-02-20 03:42

I am using QTableView\'s checkbox flag of Qt::ItemIsUserCheckable to display a checkbox in a table cell.

After reading some things on alignment in an attempt to

6条回答
  •  感动是毒
    2021-02-20 04:02

    After further investigation into delegate options I found a nice reference (unfortunately no longer available) and came up with the following hybrid using a QItemDelegate and IsUserCheckable.

    Essentially, you need to extend QItemDelegate, and reimplement, using the drawCheck function to center and use the editorEvent to handle mouse and keyboard events while setting the model with the appropriate state.

    void drawCheck(QPainter* painter, QStyleOptionViewItem const& option, QRect const& rect, Qt::CheckState state) const
    

    and

    bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
    

    Also see this similar question here...

提交回复
热议问题