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 to left align or right align data in Qtreeview
Forum Updated to NodeBB v4.3 + New Features

How to left align or right align data in Qtreeview

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 6 Posters 2.7k Views 4 Watching
  • 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by VRonin
    #1

    How to left align or right align data in QTreeview

    A              B             C            D
    
    data1     data2   data3 dat4
    data2    data22   data33 dat44
    

    currently, it is coming as juggled

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      From the top of my head: return the desired Qt::Alignment for the Qt::TextAlignmentRole in your custom model.

      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
      5
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on last edited by
        #3

        A small example will help

        mrjjM 1 Reply Last reply
        0
        • Q Qt Enthusiast

          A small example will help

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @Qt-Enthusiast

          Hi
          he did make a small example :)

          https://forum.qt.io/topic/11625/solved-text-alignment-in-qtableview-cell/10

          QVariant data(const QModelIndex &index, int role)
          {
          if (role == Qt::TextAlignmentRole) {
          return Qt::AlignRight;
          }
          
          Q kshegunovK 2 Replies Last reply
          5
          • mrjjM mrjj

            @Qt-Enthusiast

            Hi
            he did make a small example :)

            https://forum.qt.io/topic/11625/solved-text-alignment-in-qtableview-cell/10

            QVariant data(const QModelIndex &index, int role)
            {
            if (role == Qt::TextAlignmentRole) {
            return Qt::AlignRight;
            }
            
            Q Offline
            Q Offline
            Qt Enthusiast
            wrote on last edited by
            #5

            @mrjj
            It is not working

            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              It's not a problem of the view, it's either the model or the delegate.
              What model are you using?

              "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
              1
              • Q Offline
                Q Offline
                Qt Enthusiast
                wrote on last edited by
                #7

                QAbstractitem model

                VRoninV 1 Reply Last reply
                0
                • mrjjM mrjj

                  @Qt-Enthusiast

                  Hi
                  he did make a small example :)

                  https://forum.qt.io/topic/11625/solved-text-alignment-in-qtableview-cell/10

                  QVariant data(const QModelIndex &index, int role)
                  {
                  if (role == Qt::TextAlignmentRole) {
                  return Qt::AlignRight;
                  }
                  
                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #8

                  @mrjj said in How to left align or right align data in Qtreeview:

                  he did make a small example

                  I want to upvote your post a million times!

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  1
                  • Q Qt Enthusiast

                    QAbstractitem model

                    VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #9

                    @Qt-Enthusiast said in How to left align or right align data in Qtreeview:

                    QAbstractitem model

                    Then @SGaist / @mrjj suggestion is the way to go

                    "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
                    0

                    • Login

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