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. QTableWidget, any easy way to make only some items tab stoppable

QTableWidget, any easy way to make only some items tab stoppable

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.3k 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.
  • jronaldJ Offline
    jronaldJ Offline
    jronald
    wrote on last edited by jronald
    #1

    Have used QTableWidgetItem::setFlags to disable ItemIsSelectable and ItemIsEditable, but the item is still tab stoppable, any easy way to make a table item tab unstoppable?

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

      Hi
      What is stoppable and unstoppable ?
      Never seen these words in relation to QTableWidgetItem :)

      jronaldJ 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        What is stoppable and unstoppable ?
        Never seen these words in relation to QTableWidgetItem :)

        jronaldJ Offline
        jronaldJ Offline
        jronald
        wrote on last edited by
        #3

        @mrjj For example

        1. a 2x2 table
        2. focus on cell (0,1)
        3. press Tab key, focus to cell(1.1) instead of cell(1,0)
          Is there any built in support for this?
        mrjjM 1 Reply Last reply
        0
        • jronaldJ jronald

          @mrjj For example

          1. a 2x2 table
          2. focus on cell (0,1)
          3. press Tab key, focus to cell(1.1) instead of cell(1,0)
            Is there any built in support for this?
          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @jronald
          HI
          I think
          http://doc.qt.io/qt-5/qabstractitemview.html#moveCursor
          can be used but I have not tested it.

          jronaldJ 1 Reply Last reply
          4
          • mrjjM mrjj

            @jronald
            HI
            I think
            http://doc.qt.io/qt-5/qabstractitemview.html#moveCursor
            can be used but I have not tested it.

            jronaldJ Offline
            jronaldJ Offline
            jronald
            wrote on last edited by jronald
            #5

            @mrjj
            Helpful
            QAbstractItemView::setCurrentIndex can be used to move to any cell
            Though not so built in, but also very good way

            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              Try reimplementing moveCursor

              
              #include <QTableWidget>
              #include <QAbstractItemModel>
              class MyTableWidget : public QTableWidget{
                  Q_OBJECT
                  Q_DISABLE_COPY(MyTableWidget)
              public:
                  explicit MyTableWidget(QWidget* parent = Q_NULLPTR)
                      :QTableWidget(parent)
                  {}
              protected:
                  QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE{
                      QModelIndex beginIdx = currentIndex();
                      QModelIndex currIdx, prevIdx;
                      if(model()){
                          for(;;){
                              currIdx = QTableWidget::moveCursor(cursorAction,modifiers);
                              if(!beginIdx.isValid())
                                  beginIdx=currIdx;
                              if(!currIdx.isValid())
                                  break;
                              if(model()->flags(currIdx) & Qt::ItemIsSelectable)
                                  break;
                              if(currIdx==beginIdx)
                                  break;
                              if(prevIdx==currIdx)
                                  break;
                              prevIdx=currIdx;
                              setCurrentIndex(currIdx);
                          }
                      }
                      return currIdx;
                  }
              
              };
              
              

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              2

              • Login

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