Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-140683

Emoji in `QAbstractTableModel` cell cause excessive padding

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 6.9.2
    • Widgets: Itemviews
    • None
    • Linux/Wayland

      When using QAbstractTableModel to return data including emoji to then be rendered by a QTableView, the resulting table appears to simply not show the cells which contain emoji:

      However, if we expand the height of the cells somewhat, we see that the data are there, but have a large amount of vertical padding:


      Sample code:

      from typing import override
      
      from PySide6.QtCore import (
          QAbstractTableModel,
          QModelIndex,
          QObject,
          QPersistentModelIndex,
          Qt,
      )
      from PySide6.QtWidgets import (
          QApplication,
          QHeaderView,
          QTableView,
          QVBoxLayout,
          QWidget,
      )
      
      TOP_LEVEL_INDEX = QModelIndex()
      
      
      class DemoModel(QAbstractTableModel):
          def __init__(self, parent: QObject | None = None) -> None:
              super().__init__(parent=parent)
              self._data = [
                  ("Foo", "Bar", "Baz"),
                  ("Spam", "🍖", "Eggs"),
                  ("Red ❤️", "G💚r💚e💚e💚n", "Blue 💙"),
                  ("⍼", "妛彁", "🂡🂢🂣🂤🂥"),
              ]
      
          @override
          def rowCount(self, /, parent: QModelIndex | QPersistentModelIndex = TOP_LEVEL_INDEX) -> int:
              return len(self._data)
      
          @override
          def columnCount(self, /, parent: QModelIndex | QPersistentModelIndex = TOP_LEVEL_INDEX) -> int:
              return len(self._data[0])
      
          @override
          def data(
              self, index: QModelIndex | QPersistentModelIndex, /, role: int = Qt.ItemDataRole.DisplayRole
          ) -> str | None:
              match role:
                  case Qt.ItemDataRole.DisplayRole:
                      return self._data[index.row()][index.column()]
                  case _:
                      return None
      
      
      class DemoTableView(QTableView):
          def __init__(self, parent: QWidget | None = None) -> None:
              super().__init__(parent=parent)
              self.setModel(DemoModel(self))
              self.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.ResizeToContents)
      
      
      class DemoWidget(QWidget):
          def __init__(self, parent: QWidget | None = None) -> None:
              super().__init__(parent=parent)
              layout = QVBoxLayout(self)
              table_view = DemoTableView(self)
              layout.addWidget(table_view)
      
      
      if __name__ == "__main__":
          app = QApplication()
          window = DemoWidget()
          window.show()
          app.exec()
      
      

       


      I'm experiencing this issue while using the PySide6 Python bindings, however I'm filing it here since I don't have any reason to believe this is an issue with PySide6 specifically. If I've made a mistake in this report, please let me know

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            thcrt Theo Court
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes