Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How do I set some characters bold in QTableWidgetItem?
Qt 6.11 is out! See what's new in the release blog

How do I set some characters bold in QTableWidgetItem?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kycho
    wrote on last edited by Kycho
    #1

    I want to bold some of the characters in the cells of the QTableWidget.

    example:)
    (the character with 't' is bold)
    "I'm table widget item!"

    QTableWidgetItem does not seem to be able to apply a font to some characters.

    How can I solve this problem?

    Thank you.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
      wrote on last edited by
      #2

      You have two options. QTableWidgetItem does not support rich text.

      1. Use the setCellWidget(..) with QLabel which support rich text
      2. User your own Custom delegate.
      for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                QLabel *lb = new QLabel("<b>D</b>eerendra");
                ui->tableWidget->setCellWidget(i,j,lb);
            }
        }
      

      Dheerendra
      @Community Service
      Certified Qt Specialist
      https://www.pthinks.com

      VRoninV 1 Reply Last reply
      2
      • dheerendraD dheerendra

        You have two options. QTableWidgetItem does not support rich text.

        1. Use the setCellWidget(..) with QLabel which support rich text
        2. User your own Custom delegate.
        for(int i=0;i<4;i++){
              for(int j=0;j<4;j++){
                  QLabel *lb = new QLabel("<b>D</b>eerendra");
                  ui->tableWidget->setCellWidget(i,j,lb);
              }
          }
        
        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        @dheerendra said in How do I set some characters bold in QTableWidgetItem?:

        User your own Custom delegate.

        https://pastebin.com/XrppLZ3m

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        5

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved