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. How to use the corner button of QTableView?

How to use the corner button of QTableView?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 4.5k 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.
  • T Offline
    T Offline
    tovax
    wrote on 10 Nov 2020, 01:00 last edited by
    #1

    Hi, all
    Click the button in the upper left corner of QTableView, the default function is to select the entire table. I want to display the "reset" text on this corner button and trigger a custom function after clicking it, such as clearing the QTableView. I did not find the signal of the corner button, and "setCornerWidget " cannot set another QPushButton correctly. Could you give me some suggestion please?
    Best regards!

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on 10 Nov 2020, 02:40 last edited by Bonnie 11 Oct 2020, 02:42
      #2

      Qt doesn't have API for that. But I think it may be done by cheating ways. :)
      And "setCornerWidget“ is a member function of QAbstractScrollArea, so it means the bottom right corner of the scroll bars.

      T 1 Reply Last reply 10 Nov 2020, 03:35
      1
      • B Bonnie
        10 Nov 2020, 02:40

        Qt doesn't have API for that. But I think it may be done by cheating ways. :)
        And "setCornerWidget“ is a member function of QAbstractScrollArea, so it means the bottom right corner of the scroll bars.

        T Offline
        T Offline
        tovax
        wrote on 10 Nov 2020, 03:35 last edited by
        #3

        @Bonnie When you said that, I found a small button in the bottom right corner. Thank you!
        "by cheating ways", is it to create a new QPushbutton covering the upper left corner please?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Bonnie
          wrote on 10 Nov 2020, 03:49 last edited by Bonnie 11 Oct 2020, 06:36
          #4

          I mean using QObject::findChild / QObject::findChildren like

          //the top left corner button should be the only button that is the tableview's direct child
          //If there are multiple, you should look for whose class name is "QTableCornerButton"
          if(auto button = ui->tableWidget->findChild<QAbstractButton*>(QString(), Qt::FindDirectChildrenOnly)) {
              //this button is not a normal button, it doesn't paint text or icon
              //so it is not easy to show text on it, the simplest way is tooltip
              button->setToolTip("Reset");
              //disconnect the connected slots to the tableview (the "selectAll" slot)
              disconnect(button, Q_NULLPTR, ui->tableWidget, Q_NULLPTR);
              //connect "clear" slot to it, here I use QTableWidget's clear, you can connect your own
              connect(button, &QAbstractButton::clicked, ui->tableWidget, &QTableWidget::clear);
          }
          

          But covering it with another button also seems to be a workable approach, you can try that

          T 1 Reply Last reply 20 Nov 2020, 03:52
          5
          • B Bonnie
            10 Nov 2020, 03:49

            I mean using QObject::findChild / QObject::findChildren like

            //the top left corner button should be the only button that is the tableview's direct child
            //If there are multiple, you should look for whose class name is "QTableCornerButton"
            if(auto button = ui->tableWidget->findChild<QAbstractButton*>(QString(), Qt::FindDirectChildrenOnly)) {
                //this button is not a normal button, it doesn't paint text or icon
                //so it is not easy to show text on it, the simplest way is tooltip
                button->setToolTip("Reset");
                //disconnect the connected slots to the tableview (the "selectAll" slot)
                disconnect(button, Q_NULLPTR, ui->tableWidget, Q_NULLPTR);
                //connect "clear" slot to it, here I use QTableWidget's clear, you can connect your own
                connect(button, &QAbstractButton::clicked, ui->tableWidget, &QTableWidget::clear);
            }
            

            But covering it with another button also seems to be a workable approach, you can try that

            T Offline
            T Offline
            tovax
            wrote on 20 Nov 2020, 03:52 last edited by
            #5

            @Bonnie Hi, Bonnie
            Your reply solved my question, thank you very much!
            I'm sorry I didn't get back to you in time.
            Best Regards!

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Juri Sedov
              wrote on 15 Mar 2022, 13:19 last edited by Juri Sedov
              #6

              with Icon

              ui->tableWidget->setStyleSheet( "QTableView QTableCornerButton::section{ background: red; border: 1px solid red; border-radius: 3px; image: url(:/bilder/ABC.ico); }");

              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