Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering the text of a vertical header in a QTableView?

Tags:

c++

qt

qtableview

I have a QTableView with the vertical header visible. By default, this header is numbered. I cannot figure out how to center the text (numbers), though. Here's what it looks like now (the red parts are the headers):

enter image description here

Here is the code I currently have. I tried applying an alignment property with CSS, but it doesn't work. Everything else seems to work via CSS (coloring), but not the text alignment.

ui->tableView->verticalHeader()->setStyleSheet(QStringLiteral("QHeaderView::section{background-color: #e5cbcb; text-align: center;}"));

How can I center the numbers?

like image 725
earth Avatar asked Feb 07 '23 00:02

earth


1 Answers

Use setDefaultAlignment()

With these flags:

Qt::AlignLeft   0x0001  Aligns with the left edge.
Qt::AlignRight  0x0002  Aligns with the right edge.
Qt::AlignHCenter    0x0004  Centers horizontally in the available space.
Qt::AlignJustify    0x0008  Justifies the text in the available space.
like image 118
Lucas Araujo Avatar answered Feb 09 '23 15:02

Lucas Araujo