fatma.ekici
fatma.ekici

Reputation: 2837

How to change the font size of QTableWidget header?

I am trying to decrease the size of the font in horizontal header of a QTableWidget. Below code does not work, font size remains unchanged.

QFont font;
font.setPointSize(7);
ui.tableWidget->horizontalHeader()->setFont(font);

How can I change the font in this case?

Upvotes: 5

Views: 24280

Answers (1)

Teh Suu
Teh Suu

Reputation: 1809

Basically there are two ways:

(1) I am not 100% sure why your code is not working, but my guess is the font you created is invalid and won't apply, usually you want to use the existing Font from the QHeaderView, manipulate it and reset it to ensure that all other settings are identical:

// Example 1
QFont font = ui.tableWidget->horizontalHeader()->font();
font.setPointSize( 42 );
ui.tableWidget->horizontalHeader()->setFont( font );

(2) Further you can use StyleSheets instead of QFont which is often easier.

// Example 2
_ui.tableWidget->horizontalHeader()->setStyleSheet("QHeaderView { font-size: 42pt; }");

Both ways have worked with Qt-4.8.3

Upvotes: 14

Related Questions