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]resizing vertical header
Forum Updated to NodeBB v4.3 + New Features

[solved]resizing vertical header

Scheduled Pinned Locked Moved General and Desktop
15 Posts 4 Posters 21.7k 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.
  • P Offline
    P Offline
    p91paul
    wrote on last edited by
    #3

    !http://db.tt/tEoiPar(where i want to bring the header)!

    I need the header to reach the black mark I made in the picture.

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

      there is a problem with your image link. it doesn't show up.

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • P Offline
        P Offline
        p91paul
        wrote on last edited by
        #5

        sorry, corrected (I hope :D)

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

          "The frozen column example":http://doc.qt.nokia.com/latest/itemviews-frozencolumn.html is not exactly what you want, but the same techniques can be used here.

          There are also 2 QTables that need to be in sync with each orther.

          Qt Certified Specialist
          www.edalsolutions.be

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

            You can try "QTableView::setColumnWidth":http://doc.qt.nokia.com/4.7/qtableview.html#setColumnWidth and set the corresponding width.

            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
              #8

              I think Paul wants something like this :
              !http://dl.dropbox.com/u/33544011/2Tables.PNG(2 tables)!

              Is that correct?

              Qt Certified Specialist
              www.edalsolutions.be

              1 Reply Last reply
              0
              • P Offline
                P Offline
                p91paul
                wrote on last edited by
                #9

                yes!
                I solved now inheriting from qheaderview and using a method to set sizehint's width, and I override sizeHint() to return a Qsize with parent's height and just set width. I consider this an ugly fix, but it works.

                what's your solution (probably better)?

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

                  I didn't have a solution 13 minutes ago. I was just testing some things for which a made a ui.

                  I don't know if it's better, but I didn't need to subclass :
                  in the constructor of the form/mainwindow where you use the 3 tables :

                  @ qDebug() << ui->tableWidget->verticalHeader()->sizeHint().width(); //get width of VHeader
                  qDebug() <<ui->tableWidget->columnWidth(0);//get width of first column

                  int HeaderWidth2 = ui->tableWidget->verticalHeader()->sizeHint().width() + ui->tableWidget->columnWidth(0);
                  
                  ui->tableWidget_2->verticalHeader()->setFixedWidth(HeaderWidth2);//set width of second VHeader@
                  

                  This doen't take in to account that the widths could be changed afterwards. In that case we will need some signals and slots.

                  Anyway I hope it helps in some way.

                  Qt Certified Specialist
                  www.edalsolutions.be

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    p91paul
                    wrote on last edited by
                    #11

                    Well, your solution is better because you haven't subclassed, but it requires the same workaround when resizing: when I resize the header (with signal/slot stuff), in my and your solution the first column ("one" in your example) is not pushed to the right.
                    instead, the header covers the column.

                    As an ugly fix, I have to do something like
                    @ int colw=ui->tblTotals->columnWidth(0);
                    ui->tblTotals->setColumnWidth(0,0);
                    ui->tblTotals->setColumnWidth(0,colw);@

                    and the table is repainted correctly.
                    thanks anyway.

                    Paolo

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

                      I understand now what you mean about the column resizing thing.

                      Glad it is working!

                      Have Qt fun!

                      Qt Certified Specialist
                      www.edalsolutions.be

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        alexisdm
                        wrote on last edited by
                        #13

                        I think you have to call the slot QTableView::updateGeometries() after resizing the header.
                        Because that slot is protected, you have to call it through QMetaObject::invokeMethod.
                        Assuming the 2 tables are named ui->tblHours and ui->tblTotals:
                        @// In the constructor
                        ...
                        // The real column resizing is done asynchronously,
                        // so you have to delay the slot with Qt::QueuedConnection
                        connect(ui->tblHours->horizontalHeader(), SIGNAL(sectionResized(int,int,int)),
                        SLOT(resizeHeader()), Qt::QueuedConnection);
                        ...

                        void YourClass::resizeHeader() {
                        int width = ui->tblHours->verticalHeader()->width() +
                        ui->tblHours->columnWidth(0);
                        ui->tblTotals->verticalHeader()->setFixedWidth(width);
                        QMetaObject::invokeMethod(ui->tblTotals, "updateGeometries");
                        }@

                        1 Reply Last reply
                        2
                        • P Offline
                          P Offline
                          p91paul
                          wrote on last edited by
                          #14

                          thanks a lot alexisdm. this worked for me. this approach has the advantage to be more clear.
                          very strange thing the QMetaObject one, it breaks everything about protected/private and so on. I think in a theorical OOP it has to be avoided, but for actual programming is very useful :D

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

                            @Alexis

                            good one!

                            Qt Certified Specialist
                            www.edalsolutions.be

                            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