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 control tab focus?

How to control tab focus?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 5.6k Views 1 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.
  • B Offline
    B Offline
    Binary91
    wrote on last edited by
    #1

    Hi,

    I've got a main_window with a table.
    Each table cell has its own QWidget window with different elements.
    In the first column, each cell contains a QTextEdit, every other cell contains QCheckBoxes.
    Now my question:
    How can I control that the focus jumps only from QTextEdit to QTextEdit by typing the TAB on keyboard?
    When QTextEdit in row 1 has focus and I press TAB, focus jumps to QCheckBox in row 1, but I want the focus to jump to QTextEdit in row 2 instead...

    Is there a way to define focus index like in html or something like this? Maybe with a layout? I don't know...

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

      Hi,

      Did you have a look at setTabOrder ?

      Hope it helps

      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
      • IamSumitI Offline
        IamSumitI Offline
        IamSumit
        wrote on last edited by
        #3

        and also you can change focus policy as no focus of QCheckBoxes.

        "Go":http://www.qtforum.org/article/15660/disable-tab-order.html

        Be Cute

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Binary91
          wrote on last edited by
          #4

          Hi again,

          first of all thank you for the support!
          I took a look at setTabOrder, but there is something wrong with it.
          I have a QWidget based subclass "main_window" with a table within.
          Each table cell has it's own QWidget based child window "table_cell". This class "table_cell" contains things like QTextEdit, QCheckBox etc.
          I create those child widgets with a loop within a loop (rows & columns):
          @for(int i = 0; i < table->rowCount(); i++)
          {
          for(int j = 0; j < table->columnCount(); j++)
          {
          table_cell* cell; // <-- QWidget class
          if(j == 0)
          {
          QWidget* cell_widget = table->cellWidget(i-1, j);
          table_cell* cell_last = qobject_cast<table_cell*> (cell_widget);
          cell = new table_cell(this, "textedit", "cell", i, j); // <--- creating a table_cell widget with a QTextEdit
          this->setTabOrder(cell_last->textedit, cell->textedit); // <--- trying to use setTabOrder
          }
          }
          }@
          Problem is, that since I wrote the setTabOrder command, my program starts but stops executing after 0.5 seconds without displaying the window...
          No compiler errors, just closing the exe file directly after running it...

          What's wrong with my command?

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Binary91
            wrote on last edited by
            #5

            I think it's all weird because I use those widgets in a table, right?

            Maybe someone can help me finding a better way to realize the following:

            • Creating a mainwindow with a table and a button next to the table (QHBoxLayout maybe?)
            • table should have 20 rows and 10 columns
            • in column 1, every cell should contain a QTextEdit (full size), the other column cells should contain QCheckBoxes (horizontally & vertically centered --> maybe also QHBoxLayout)
            • QTextEdit in row 1 should have focus on program start
            • Focus should jump from QTextEdit to QTextEdit by typing TAB key
            • on clicking button, it should be possible to get information about all the cell widgets (contents of QTextEdit, checkstate of QCheckBox).

            How do I realize this best?
            Thank's...

            EDIT:
            Read a bit about QTableWidget TAB management --> tables have it's own tabfocuspolicy which denies using setTabOrder or stuff like that.
            Solution:
            @table->setTabKeyNavigation(false); // disable table's focus management
            table->setFocusPolicy(Qt::NoFocus);
            textedit->setFocusPolicy(Qt::StrongFocus); // it also works without that line, but I do not understand why...
            @

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

              There's something that's intriguing, since all cells have different widgets. What's the purpose of your QTableWidget ? If you don't use any model a QWidget with a QGridLayout would probably be better

              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

              • Login

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