QHeaderView when I set up and down arrow image , then header text will not drawtext with aligncenter
-
my QT version is 6.8.0, using visual studio 2022
When I user styleSheet ,then Column 3 Text will not draw in center.
my sample code:
int main(int argc, char argv[])
{
QApplication a(argc, argv);
QWidget window;
QFrame pFrame = new QFrame(&window);
pFrame->setFixedSize(500, 500);
QVBoxLayout* layout = new QVBoxLayout(pFrame);
QTableView* pList = new QTableView(pFrame);
pList->setFixedSize(400, 400);
pList->setWordWrap(false);
pList->setShowGrid(false);
pList->setSelectionBehavior(QAbstractItemView::SelectRows);
pList->setSortingEnabled(true);
pList->setAlternatingRowColors(true);
pList->horizontalHeader()->setStyleSheet("QHeaderView::down-arrow{image:url(:/test/image/arrow_down.png);}
QHeaderView::up-arrow{image:url(:/test/image/arrow_up.png);}");
pList->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
QStandardItemModel model(5, 5);
model.setHorizontalHeaderLabels(QStringList() << "Column 1" << "Column 2" << "Column 3" << "Column 4" << "Column 5");
for (int row = 0; row < 5; ++row)
{
for (int column = 0; column < 5; ++column)
{
QStandardItem* item = new QStandardItem(QString("Row%1, Col%2").arg(row + 1).arg(column + 1));
model.setItem(row, column, item);
}
}
pList->setModel(&model);
window.show();
return a.exec();
} -
That's a problem of the windowsvista style which draws the arrows on top of the header instead to the right (like all others) and QStyleSheetStyle does not know this/can not know it. Don't know how to fix it though.
-
@Christian-Ehrlicher Yes, it is window style show, when linux the arrow is in Header Text right, how to set to arrow to right under window system? Thanks.