Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Bold QStringlist



  • What is the preferred way to create a bold QStringlist?



  • Qstringlist doesn't care about attributes like bold. That is the responsbility of how you render the string in in a widget. I "think" that if you add markup to the string such as QWidget::SetText("<b>bold text</b>") it would have the desired effect when rendered.



  • I have a QTableWidget and when I call setHorizontalHeaderLabels(head), where head is a QStringList, I want the header text to be set to bold. But using QStringList is probably not a good approach?



  • @Buller
    This has nothing to do with you setting the the labels from a QStringList.

    There are various ways of achieving the bolding. You access the header labels via QTableWidget::horizontalHeader(). Then you could either

    QFont font = tableWidget->horizontalHeader()->font();
    font.setBold(true);
    tableWidget->horizontalHeader()->setFont(font);
    

    or

    tableWidget->horizontalHeader()->setStyleSheet("QHeaderView { font-weight: bold; }")
    

    There are also ways of accessing individual header columns if you want that.



  • The stylesheet option works fine. Thanks.


  • Lifetime Qt Champion

    Hi @Buller,

    thanks for the feedback. So please mark this topic as SOLVED now. Thanks!


Log in to reply