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. Alignment of Table Horizontal Headers

Alignment of Table Horizontal Headers

Scheduled Pinned Locked Moved General and Desktop
6 Posts 5 Posters 6.8k Views 1 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.
  • S Offline
    S Offline
    ShawnG
    wrote on last edited by
    #1

    Hello,
    I would like to set the alignment for the horizontal header differently for each column, but it may not be the same as the items in their corresponding column. Help?
    Thanks

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      Just return the proper alignment from your QAbstractItemModel::headerData implementation for the TextAlignmentRole.

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • S Offline
        S Offline
        ShawnG
        wrote on last edited by
        #3

        Being a Qt newbie, could you point me in the correct direction of some sample code to review? Thanks!

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          You can read the docu of QAbstractItemModel::headerData. Afaik, there is no official example, doing this.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • EddyE Offline
            EddyE Offline
            Eddy
            wrote on last edited by
            #5

            you could use something like :
            @
            QVariant TableModel::headerData ( int section, Qt::Orientation orientation, int role ) const
            {
            ...other stuff
            if ( orientation == Qt::Horizontal )
            {
            ...

            if(role == Qt::TextAlignmentRole ){

                       if(col == 1){
                          return Qt::AlignRight;
                       }
                       else{
                          return Qt::AlignLeft;
                       }
            

            return QVariant();
            }@

            hope this gives you some directions

            Qt Certified Specialist
            www.edalsolutions.be

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              @ShawnG:

              Could you tell us what model and what view you are using? Are you using a QStandardItemModel with a QTableView, or a QTableWidget? Or something else?

              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