Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Set alignment for QTreeView cells

Set alignment for QTreeView cells

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 4 Posters 2.8k 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.
  • L Offline
    L Offline
    LeeHyunKyu
    wrote on last edited by
    #1

    Re: Set alignment for QTreeView cells

    QTreeView Cell Alignment

    QStandardItem:: setTextAlignment(Qt::Alignment)

    so

    my_model ->item(row, column)->setTextAlignment(Qt::AlignCenter);

    Please suggest me if there is another way.

    JonBJ 1 Reply Last reply
    0
    • L LeeHyunKyu

      Re: Set alignment for QTreeView cells

      QTreeView Cell Alignment

      QStandardItem:: setTextAlignment(Qt::Alignment)

      so

      my_model ->item(row, column)->setTextAlignment(Qt::AlignCenter);

      Please suggest me if there is another way.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @LeeHyunKyu
      Why do you want another way?

      1 Reply Last reply
      0
      • JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @Denni-0
        I don't know if that is a question. The way Qt works is that alignments etc. are on a cell-by-cell basis, not a complete row/column. That's just how it is. However, using Qt data() way of doing things, among the roles (https://doc.qt.io/qt-5/qt.html#ItemDataRole-enum) there is e.g. Qt::TextAlignmentRole, so one can write code to affect all cells in a row/column via that return result instead of actually setting alignment on individual cells.

        1 Reply Last reply
        0
        • JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Denni-0 said in Set alignment for QTreeView cells:

          but I know you can affect an entire column and/or row within a QTreeView as I have done it but cannot find it now

          You would look at index.row() or index.column() to affect row/column:

              def data(self, index, role):
                  if (role == QtCore.Qt.TextAlignmentRole):
                      if index.row() == whatever or index.column() == something:
                          return QtCore.Qt.AlignHCenter
          
          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            You can use a QIdentityProxyModel between your orignal data and your view. You can alter there just what you want.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            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