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.
  • tovaxT Offline
    tovaxT Offline
    tovax
    wrote on 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 last edited by Bonnie
      #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.

      tovaxT 1 Reply Last reply
      1
      • B Bonnie

        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.

        tovaxT Offline
        tovaxT Offline
        tovax
        wrote on 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 last edited by Bonnie
          #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

          tovaxT 1 Reply Last reply
          5
          • B Bonnie

            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

            tovaxT Offline
            tovaxT Offline
            tovax
            wrote on 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 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