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. QTableView: how to take screenshot (grab widget) of complete content
Forum Update on Monday, May 27th 2025

QTableView: how to take screenshot (grab widget) of complete content

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt5qtableviewscreenshotgrab
6 Posts 4 Posters 1.9k 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.
  • M Offline
    M Offline
    markus.liebe
    wrote on 14 Mar 2016, 12:11 last edited by
    #1

    Hello,

    is it possible, to take a screenshot of the complete widget that is contained in a QTableView?
    Think QScrollArea->widget()->grab().

    Background: I want to create a kind of overview scrollbar like SublimeText does.
    I want to display a miniature version of the complete contents of the QTableView at the side of the TableView to be able to

    • get an overview
    • use it to navigate (scroll) in the tableview

    Thus it is important for me, to get a representation of all the content in the QTableView and not just the parts that are visible through the viewport.

    Best regards,
    Markus

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      QtTester
      wrote on 3 Jul 2021, 02:08 last edited by
      #2

      Hi, Markus,
      did you finish this function? I also have this problem. anyone can help?

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ChrisW67
        wrote on 3 Jul 2021, 03:03 last edited by ChrisW67 7 Mar 2021, 03:05
        #3

        There is no "complete contents", only the portion that fits in the viewport is drawn. With model batch loading, the view may not even has access to all the data needed.

        Q 1 Reply Last reply 3 Jul 2021, 05:56
        1
        • C ChrisW67
          3 Jul 2021, 03:03

          There is no "complete contents", only the portion that fits in the viewport is drawn. With model batch loading, the view may not even has access to all the data needed.

          Q Offline
          Q Offline
          QtTester
          wrote on 3 Jul 2021, 05:56 last edited by
          #4

          @ChrisW67
          Let's just change a widget, like Qtablewidget, I add data to it more than a vertical screen, (maybe need 2 vertical screen). the widget will show scrollbar when it cannot show all.
          Now i snap the content, how to see the full content in one picture? do i need scroll and take two picture, and finally combine to one picture? is there a combination algorithm inside Qt? if not , should we use opencv or halcon?

          M 1 Reply Last reply 3 Jul 2021, 07:25
          0
          • Q QtTester
            3 Jul 2021, 05:56

            @ChrisW67
            Let's just change a widget, like Qtablewidget, I add data to it more than a vertical screen, (maybe need 2 vertical screen). the widget will show scrollbar when it cannot show all.
            Now i snap the content, how to see the full content in one picture? do i need scroll and take two picture, and finally combine to one picture? is there a combination algorithm inside Qt? if not , should we use opencv or halcon?

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 3 Jul 2021, 07:25 last edited by
            #5

            @QtTester

            Hi
            Scrolling and combine to one picture could work but will be messy to get to align up.

            You could place the table in a scroll area so we can freely resize it

            alt text

            and then you can ask it to render to a pixmap like this

            void MainWindow::on_pushButton_pressed()
            {
                // for readability
                auto table = ui->tableWidget;
                auto vheader = ui->tableWidget->verticalHeader();
                auto hheader = ui->tableWidget->horizontalHeader();
                // ask it to resize to size of all its text
                vheader->setSectionResizeMode( QHeaderView::ResizeToContents );
                hheader->setSectionResizeMode( QHeaderView::ResizeToContents );
                // tell it we never want scrollbars so they are not shown disabled
                vheader->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
                hheader->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
                // loop all rows and cols and grap sizes
                int iWidth = 0;
                int iHeight = 0;
                for (int i = 0; i < table->columnCount(); i++) {
                    iWidth += hheader->sectionSize(i);
                }
                iWidth += vheader->width();
                for (int i = 0; i < ui->tableWidget->rowCount(); i++) {
                    iHeight += vheader->sectionSize(i);
                }
                iHeight += hheader->height();
                QSize oldSize = table->size();
                // now resize it to the size we just summed up
                table->resize(iWidth, iHeight);
                // ask it to renader to a pixmap
                QPixmap pixmap(ui->tableWidget->size());
                table->render(&pixmap);
                pixmap.save("e:/test.png");
                // restore org size
                table->resize(oldSize);
            }
            

            and you get a pixmap with it all.

            alt text

            Q 1 Reply Last reply 5 Jul 2021, 00:45
            0
            • M mrjj
              3 Jul 2021, 07:25

              @QtTester

              Hi
              Scrolling and combine to one picture could work but will be messy to get to align up.

              You could place the table in a scroll area so we can freely resize it

              alt text

              and then you can ask it to render to a pixmap like this

              void MainWindow::on_pushButton_pressed()
              {
                  // for readability
                  auto table = ui->tableWidget;
                  auto vheader = ui->tableWidget->verticalHeader();
                  auto hheader = ui->tableWidget->horizontalHeader();
                  // ask it to resize to size of all its text
                  vheader->setSectionResizeMode( QHeaderView::ResizeToContents );
                  hheader->setSectionResizeMode( QHeaderView::ResizeToContents );
                  // tell it we never want scrollbars so they are not shown disabled
                  vheader->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
                  hheader->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
                  // loop all rows and cols and grap sizes
                  int iWidth = 0;
                  int iHeight = 0;
                  for (int i = 0; i < table->columnCount(); i++) {
                      iWidth += hheader->sectionSize(i);
                  }
                  iWidth += vheader->width();
                  for (int i = 0; i < ui->tableWidget->rowCount(); i++) {
                      iHeight += vheader->sectionSize(i);
                  }
                  iHeight += hheader->height();
                  QSize oldSize = table->size();
                  // now resize it to the size we just summed up
                  table->resize(iWidth, iHeight);
                  // ask it to renader to a pixmap
                  QPixmap pixmap(ui->tableWidget->size());
                  table->render(&pixmap);
                  pixmap.save("e:/test.png");
                  // restore org size
                  table->resize(oldSize);
              }
              

              and you get a pixmap with it all.

              alt text

              Q Offline
              Q Offline
              QtTester
              wrote on 5 Jul 2021, 00:45 last edited by
              #6

              @mrjj seems a great idea, i will try later and thank you.

              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