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. QHeaderView: Stretch *and* ResizeToContents?
Forum Updated to NodeBB v4.3 + New Features

QHeaderView: Stretch *and* ResizeToContents?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 3.7k Views 2 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by mzimmers
    #1

    Hi all -

    This probably sounds weird, but I'm trying to format a QTableView so that each column's content is fully visible.

    When I use ResizeToContents mode, it looks like this:
    resize.PNG

    and when I use Stretch, it looks like this:
    stretch.PNG

    I could use minimum column widths, I suppose, but...is there a better way to to it?

    Thanks...

    kshegunovK 1 Reply Last reply
    0
    • mzimmersM mzimmers

      Hi all -

      This probably sounds weird, but I'm trying to format a QTableView so that each column's content is fully visible.

      When I use ResizeToContents mode, it looks like this:
      resize.PNG

      and when I use Stretch, it looks like this:
      stretch.PNG

      I could use minimum column widths, I suppose, but...is there a better way to to it?

      Thanks...

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      Can you show what exactly you're doing (code)?
      I usually use:

      view->horizontalHeader()->setSectionResizeMode(...);
      

      To tweak the appearance of the sections, but it's hard to tell if that's what you're looking for exactly.

      Read and abide by the Qt Code of Conduct

      mzimmersM 1 Reply Last reply
      2
      • kshegunovK kshegunov

        Can you show what exactly you're doing (code)?
        I usually use:

        view->horizontalHeader()->setSectionResizeMode(...);
        

        To tweak the appearance of the sections, but it's hard to tell if that's what you're looking for exactly.

        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        @kshegunov

            QSizePolicy qsp;
            QHeaderView *qhv;
        
            // set the size policy to expanding.
            qsp.setHorizontalPolicy(QSizePolicy::Expanding);
            qsp.setVerticalPolicy(QSizePolicy::Expanding);
        
            // set the table to stretch mode.
            qhv = ui->tableView->horizontalHeader();
            qhv->setSectionResizeMode(QHeaderView::Stretch);
        
        kshegunovK 1 Reply Last reply
        0
        • mzimmersM mzimmers

          @kshegunov

              QSizePolicy qsp;
              QHeaderView *qhv;
          
              // set the size policy to expanding.
              qsp.setHorizontalPolicy(QSizePolicy::Expanding);
              qsp.setVerticalPolicy(QSizePolicy::Expanding);
          
              // set the table to stretch mode.
              qhv = ui->tableView->horizontalHeader();
              qhv->setSectionResizeMode(QHeaderView::Stretch);
          
          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          That's an overload that sets it uniformly to all sections. You can use the overload that takes a section number to have different behaviours between the columns.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          2
          • mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #5

            so, ResizeToContents for the ones that tend to be wider, and stretch for the rest?

            kshegunovK 1 Reply Last reply
            0
            • mzimmersM mzimmers

              so, ResizeToContents for the ones that tend to be wider, and stretch for the rest?

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              Well, yes, it's finicky, but should be enough to get it to something you like.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              0
              • mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on last edited by
                #7

                I think this will work:
                bestsofar.PNG

                Not beautiful, but definitely better. Thanks, kshegunov.

                1 Reply Last reply
                1
                • KaguroK Offline
                  KaguroK Offline
                  Kaguro
                  wrote on last edited by Kaguro
                  #8

                  Hi! Is there any better solution for this problem, or still is this the best way?

                  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