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 reset tab order in QHeaderView?
Forum Updated to NodeBB v4.3 + New Features

How to reset tab order in QHeaderView?

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 2 Posters 1.1k Views 2 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    setTabOrder comes to mind for that.

    As for your complex expression, it's up to you to build a parser for it.

    If it's a simple "and" statement, you could build a hash with a vector of column and the value that should be checked. And then use that hash to inspect all the elements that forms the expression.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    D 2 Replies Last reply
    1
    • SGaistS SGaist

      Hi,

      setTabOrder comes to mind for that.

      As for your complex expression, it's up to you to build a parser for it.

      If it's a simple "and" statement, you could build a hash with a vector of column and the value that should be checked. And then use that hash to inspect all the elements that forms the expression.

      D Offline
      D Offline
      deleted385
      wrote on last edited by deleted385
      #3

      @SGaist, tried if(i > 0) setTabOrder(lineEdits[i - 1], edit); and if(i > 0) QWidget::setTabOrder(lineEdits[i - 1], edit); in the for loop where I add those QLineEdit with and without table->setFocusPolicy(Qt::ClickFocus);. Doesn't work.

      EDIT
      Also tried setFocusPolicy(Qt::TabFocus); in the constructor of TableHeader.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        Then maybe an event filter.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        D 1 Reply Last reply
        0
        • SGaistS SGaist

          Then maybe an event filter.

          D Offline
          D Offline
          deleted385
          wrote on last edited by
          #5

          @SGaist, not sure whether I've implemented in correct way in right place. Here's what I've in the subclass of QHeaderView:

          bool TableHeader::eventFilter(QObject *o, QEvent *e){
              for (int i = 0; i < lineEdits.size(); i++) {
                  qDebug() << "here";
                  if(lineEdits[i] != o) continue;
                  if(e->type() != QEvent::KeyPress) return false;
                  auto event = static_cast<QKeyEvent*>(e);
                  if(event->key() != Qt::Key_Tab) return false;
                  if(i == lineEdits.size()) lineEdits[0]->setFocus(Qt::FocusReason::OtherFocusReason);
                  else lineEdits[i + 1]->setFocus(Qt::FocusReason::OtherFocusReason);
                  return true;
              }
              return QHeaderView::eventFilter(o, e);
          }
          

          I don't see it printing here in Qt Creator's output window. One more thing, when I don't have any table cell visible, TAB works automatically BUT if I have any table cell visible, it doesn't work:

          x2.gif

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            You did you install the filter ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            D 1 Reply Last reply
            1
            • SGaistS SGaist

              You did you install the filter ?

              D Offline
              D Offline
              deleted385
              wrote on last edited by
              #7

              @SGaist, missed that, now it works. Thanks. Two more question:

              1. do I have to uninstall the filter when I remove some of those line edits?
              2. do I have to call line->disconnect() as I remove and delete line edit or it'll be automatically disconnected when I delete?
              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #8
                1. do you mean delete ? Then no
                2. nothing particular to do.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                D 1 Reply Last reply
                1
                • SGaistS SGaist
                  1. do you mean delete ? Then no
                  2. nothing particular to do.
                  D Offline
                  D Offline
                  deleted385
                  wrote on last edited by
                  #9

                  @SGaist, yes with the keyword delete line or line.deleteLater().

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    So the answer is no.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Hi,

                      setTabOrder comes to mind for that.

                      As for your complex expression, it's up to you to build a parser for it.

                      If it's a simple "and" statement, you could build a hash with a vector of column and the value that should be checked. And then use that hash to inspect all the elements that forms the expression.

                      D Offline
                      D Offline
                      deleted385
                      wrote on last edited by
                      #11

                      @SGaist, QSqlTableModel actually has that feature and I can give it an expression like that in its setFilter to accept/reject rows like this:

                      x3.gif

                      Here's the code I used for that:

                      void TableWidget::refreshModel(){
                          auto queries = tableHeader->getQueries();
                          QString expression;
                          for (int i = 0; i < queries.size(); i++) {
                              if(queries[i] == "") continue;
                              auto column = tableModel->headerData(i, Qt::Horizontal).toString() + " " + queries[i] + " AND ";
                              expression += column;
                          }
                          tableModel->setFilter(expression.left(expression.length() - 5)); // -5 to remove last " AND "
                          if(tableModel->lastError().type() != QSqlError::NoError){
                              tableModel->setFilter(""); // do someting else here if you want
                              tableModel->select();
                          }
                          while (tableModel->canFetchMore()) tableModel->fetchMore();
                          countLable->setText(QString::number(tableModel->rowCount()));
                      }
                      
                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        Is it just informational or is there a question related ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        D 1 Reply Last reply
                        0
                        • SGaistS SGaist

                          Is it just informational or is there a question related ?

                          D Offline
                          D Offline
                          deleted385
                          wrote on last edited by
                          #13

                          @SGaist, Informational

                          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