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. Multiple fonts in a QTableWidgetItem?
Qt 6.11 is out! See what's new in the release blog

Multiple fonts in a QTableWidgetItem?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 508 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.
  • P Offline
    P Offline
    Publicnamer
    wrote on last edited by
    #1

    It's possible to do a setFont on a QTableWidgetItem, but is it also possible to have text with more than one font inside of a QTableWidgetItem?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by ChrisW67
      #2

      Not out of the box.

      You could provide a QItemDelegate that interprets the item value as some form of rich text, renders it however it wants in QItemDelegate::paint(), and ensures a suitable editor is provided by QItemDelegate::createEditor().

      P 1 Reply Last reply
      4
      • C ChrisW67

        Not out of the box.

        You could provide a QItemDelegate that interprets the item value as some form of rich text, renders it however it wants in QItemDelegate::paint(), and ensures a suitable editor is provided by QItemDelegate::createEditor().

        P Offline
        P Offline
        Publicnamer
        wrote on last edited by
        #3

        @ChrisW67 The problem I'm trying to solve is that I want to align the text in two adjacent cells. One has let's say 12 point font, and the other has 24 point. But I want their baseline to be the same. So I thought that in the 12 point cell I could add a single space character that is 24 point and that would align them.
        Maybe what I need instead is an internal top margin.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          Have you tried having your model return Qt::AlignLeft | Qt::AlignBaseline for the Qt::TextAlignmentRole to see what happens? (No guarantees, but it might scratch the itch)

          You can also use a delegate to render plain text however you want. If the same delegate is used on the affected columns then it could position the text of both to have the baseline a consistent position relative to the bottom of the cell.

          P 1 Reply Last reply
          0
          • C ChrisW67

            Have you tried having your model return Qt::AlignLeft | Qt::AlignBaseline for the Qt::TextAlignmentRole to see what happens? (No guarantees, but it might scratch the itch)

            You can also use a delegate to render plain text however you want. If the same delegate is used on the affected columns then it could position the text of both to have the baseline a consistent position relative to the bottom of the cell.

            P Offline
            P Offline
            Publicnamer
            wrote on last edited by
            #5

            @ChrisW67 Setting the alignment of the cell to Qt::AlignBaseline didn't help. The baseline pertains to only the one cell.

            This seems to show a design flaw of the table view.

            1 Reply Last reply
            0

            • Login

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