How to set current cell color in a tableview and how to set text centerAligned
-
If you're using
QStandardItemModel
alignment can be set directly on the item when you create it:auto item = new QStandardItem("Hello"); item->setTextAlignment(Qt::AlignCenter);
You can also set the foreground/background color of the cell with
item->setForeground(Qt::red); item->setBackground(Qt::blue);
If you want to change the color of the selected item you can use a stylesheet:
table_view->setStyleSheet("QTableView { selection-color: yellow; selection-background-color: green; }");
-
If you're using
QStandardItemModel
alignment can be set directly on the item when you create it:auto item = new QStandardItem("Hello"); item->setTextAlignment(Qt::AlignCenter);
You can also set the foreground/background color of the cell with
item->setForeground(Qt::red); item->setBackground(Qt::blue);
If you want to change the color of the selected item you can use a stylesheet:
table_view->setStyleSheet("QTableView { selection-color: yellow; selection-background-color: green; }");
@Chris-Kawa
thanks for replying.
i'm using QmodelIndex to set data into cell not QstandardItem.
than how to do the same -
If you're using
QStandardItemModel
alignment can be set directly on the item when you create it:auto item = new QStandardItem("Hello"); item->setTextAlignment(Qt::AlignCenter);
You can also set the foreground/background color of the cell with
item->setForeground(Qt::red); item->setBackground(Qt::blue);
If you want to change the color of the selected item you can use a stylesheet:
table_view->setStyleSheet("QTableView { selection-color: yellow; selection-background-color: green; }");
@Chris-Kawa
thanks chris,
i got it thanks a lot.