c++ - 在 QTableView 中将垂直标题的文本居中?

标签 c++ qt qtableview

我有一个QTableView,它的垂直标题可见。默认情况下,此 header 已编号。不过,我不知道如何将文本(数字)居中。这是它现在的样子(红色部分是标题):

enter image description here

这是我目前拥有的代码。我尝试使用 CSS 应用对齐属性,但它不起作用。其他一切似乎都通过 CSS(着色)工作,但不是文本对齐。

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

如何让数字居中?

最佳答案

使用setDefaultAlignment()

使用这些标志:

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.

关于c++ - 在 QTableView 中将垂直标题的文本居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37232302/

相关文章:

android - 如何将相机预览流从 android 连接到 Qt5?

qt - 如何在 QTableView 中为当前项设置样式表

c++ - 如何确保仅在 C++ 中提供时才使用特定的类功能?

c++ - C++ 编译器如何编译变量名?

c++ - Qt Creator 运行报错

qt - 使用QWebEngine渲染图像

c++ - 从未知指针转换为类;如何检查有效性?

C++ "Variable not declared in this scope"- 再次

python-3.x - 在 QTableView 中正确使用 QComboBox - 设置数据和清除 QComboBox 的问题

python - 如何在 QTableWidget 中使特定单元格可编辑并保留其余单元格不可编辑?