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. Is it possible to get the width of a vertical header section in a QTableView?
Forum Updated to NodeBB v4.3 + New Features

Is it possible to get the width of a vertical header section in a QTableView?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 840 Views
  • 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.
  • U Offline
    U Offline
    user13
    wrote on 24 Feb 2022, 15:21 last edited by
    #1

    Hey guys, I can't find a way to get the width of a vertical header section in a QTableView with both vertical and horizontal headers.
    I have read the documentation and the only things I found are int QHeaderView::sectionSize(int logicalIndex) const which returns only the height of the section (for vertical headers) and int QHeaderView::length() const which returns the length along the orientation of the header (after a few tests I've found that this is greather than the section width and I don't know why).
    Any help would be highly appreciated!!

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 24 Feb 2022, 15:26 last edited by
      #2

      To get the row of a height you can use QTableView::rowHeight(int), to get the widget use QTableView::columnWidth(int)

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      U 1 Reply Last reply 24 Feb 2022, 15:48
      1
      • C Christian Ehrlicher
        24 Feb 2022, 15:26

        To get the row of a height you can use QTableView::rowHeight(int), to get the widget use QTableView::columnWidth(int)

        U Offline
        U Offline
        user13
        wrote on 24 Feb 2022, 15:48 last edited by user13
        #3

        @Christian-Ehrlicher said in Is it possible to get the width of a vertical header section in a QTableView?:

        To get the row of a height you can use QTableView::rowHeight(int), to get the widget use QTableView::columnWidth(int)

        Thank you for the reply!
        Is there any similar method in QHeaderView?
        What I'm trying to do is to place a QLineEdit over a double clicked header section so I defined a QHeaderView subclass and whenever a section (both horizontal or vertical) is double clicked a QLineEdit appears on top of that section.
        I was inspired by this post.

        What i have is something like this:

        void CustomHeader::onSectionDoubleClicked(int section)
        {
            qDebug() << length();
            qDebug() << height();
        
            sectionDoubleClicked = section;
            lineEdit = new QLineEdit(this);
        
        //color changed just for testing
            QPalette *palette = new QPalette();
            palette->setColor(QPalette::Base,Qt::gray);
            lineEdit->setPalette(*palette);
        
            if(orientation() == Qt::Horizontal)
                lineEdit->setGeometry(sectionViewportPosition(section), 0, sectionSize(section), height());
            else if(orientation() == Qt::Vertical)
                lineEdit->setGeometry(0, sectionViewportPosition(section), length(), sectionSize(section));
            lineEdit->show();
            lineEdit->setFocus();
            connect(lineEdit, SIGNAL(editingFinished()), this, SLOT(onEditingFinished()));
        }
        

        In the case orientation() == Qt::vertical the QLineEdit which shows up is larger than the section because lenght() is greather than the section width.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 24 Feb 2022, 15:49 last edited by
          #4

          QHeaderView is a QWidget, so it has QWidget::size()

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          U 1 Reply Last reply 24 Feb 2022, 15:59
          3
          • C Christian Ehrlicher
            24 Feb 2022, 15:49

            QHeaderView is a QWidget, so it has QWidget::size()

            U Offline
            U Offline
            user13
            wrote on 24 Feb 2022, 15:59 last edited by
            #5

            @Christian-Ehrlicher said in Is it possible to get the width of a vertical header section in a QTableView?:

            QHeaderView is a QWidget, so it has QWidget::size()

            Thank you so much! With size().width() everything works fine!

            1 Reply Last reply
            0

            1/5

            24 Feb 2022, 15:21

            • Login

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