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. [SOLVED] QTableView - Resize of several columns
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QTableView - Resize of several columns

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 7.9k 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.
  • O Offline
    O Offline
    Octani
    wrote on last edited by
    #1

    Hello,

    i would like to know if it exists any way to change the width of several columns at the same time. I mean that the user can select several columns and when he resizes one of this, it resizes other columns selected. I don't know if i am understandable.

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

      You are understandable - you are talking about something that exists in MS Excel for example, right? AFAIK there's no such option available straight out of the box. But implementing one shouldn't be too much of a hassle. Just derive from QTableView and create your own class where you can implement that option.

      Edit: typos.

      "Do not judge, and you will never be mistaken." - Jean-Jacques Rousseau

      1 Reply Last reply
      0
      • O Offline
        O Offline
        Octani
        wrote on last edited by
        #3

        Yes, exactly the same option exists in MS Excel. The problem is I don't find any signal called when a column is resized but only a slot :
        @void QTableView::columnResized ( int column, int oldWidth, int newWidth ) [protected slot]@

        So I don't understand how exploit such slot in order to realize what i mean.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          felipe.c.sousa
          wrote on last edited by
          #4

          Its not what you want, but using that you resize the columns.

          @ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);@

          From all, to all.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            d2uriel
            wrote on last edited by
            #5

            There is a signal emitted after resizing the columns:
            @void QHeaderView::sectionResized ( int logicalIndex, int oldSize, int newSize ) [signal]@
            You can connect to that one and create a slot where you will resize all selected columns accordingly.

            "Do not judge, and you will never be mistaken." - Jean-Jacques Rousseau

            1 Reply Last reply
            0
            • O Offline
              O Offline
              Octani
              wrote on last edited by
              #6

              Perfect, it works now but the user must select all the column not only some rows:

              the connect :

              @connect (tableView->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(onColumnResized(int, int, int)));
              @

              the slot :

              @void MyClass::onColumnResized (int logicalIndex, int oldSize, int newSize)
              {
              unsigned int d;

              if( sender() == tableView->horizontalHeader())
              {
                  int nbColSelected = tableView->selectionModel()->selectedColumns(0).size();
                  int size  = tableView->columnWidth(tableView->horizontalHeader()->visualIndex(logicalIndex));
              

              for(d = 0; d < nbColSelected; ++d)
              {
              tableView->setColumnWidth( tableView->selectionModel()->selectedColumns(0)[d].column(), size );
              }
              }
              }@

              1 Reply Last reply
              0
              • D Offline
                D Offline
                d2uriel
                wrote on last edited by
                #7

                Umm, do you still have a problem? Cause I can't really tell from your post if this problem is solved or not ;-).

                "Do not judge, and you will never be mistaken." - Jean-Jacques Rousseau

                1 Reply Last reply
                0
                • O Offline
                  O Offline
                  Octani
                  wrote on last edited by
                  #8

                  Hum no it's perfect :)

                  Where can I put "SOLVED" my topic? I don't find.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    d2uriel
                    wrote on last edited by
                    #9

                    Just edit your first post.

                    "Do not judge, and you will never be mistaken." - Jean-Jacques Rousseau

                    1 Reply Last reply
                    0
                    • O Offline
                      O Offline
                      Octani
                      wrote on last edited by
                      #10

                      Thanks for all d2uriel.

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        d2uriel
                        wrote on last edited by
                        #11

                        You are welcome. Glad I could be of help.

                        "Do not judge, and you will never be mistaken." - Jean-Jacques Rousseau

                        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