TableView Spinbox HAlignment
Solved
General and Desktop
-
Hi,
I have a table view to which I provide values as doubles and I get the following.
I would like the values centered in the column. So I created a new delegate and attached it to the TableView.
Now when I edit the values they are centered in the Spinbox, but when they are not edited they are not.
Why are the values only centered in edit mode and how can I keep the values centered?
-
@Bert59 please provide a MWE(minimal workable example)
It seems that your delegate only sets the editor alignment but not the unedited text, a possible solution is to override the initStyleOption method:
class StyledItemDelegate: public QStyledItemDelegate{ public: using QStyledItemDelegate::QStyledItemDelegate; protected: void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const{ QStyledItemDelegate::initStyleOption(option, index); option->displayAlignment = Qt::AlignCenter; } };
-
@Bert59 said in TableView Spinbox HAlignment:
but when they are not edited they are not.
You should take a look at the Qt::TextAlignmentRole