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. TabOrder children
Forum Updated to NodeBB v4.3 + New Features

TabOrder children

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 6.8k 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.
  • W Offline
    W Offline
    Wurstinator
    wrote on last edited by
    #1

    Hello,
    look at this window example: http://pbrd.co/QEHdDP
    !http://pasteboard.s3.amazonaws.com/images/1348661304914253.png(layout example)!
    It contains two custom widgets (which, for simplicity, contain not more than two QLineEdits) and a QPushButton, and everything inside a QVBoxLayout.
    I want the tab order (you press the tab key to move the focus to another widget) to be like this:

    LineEdit top left

    LineEdit top right

    PushButton bottom

    LineEdit center left

    LineEdit center right

    The problem is, that you can't just go into the implementation of the custom widget. You have no access to it's children. So all you can do is this:

    custom widget top

    PushButton bottom

    custom widget center

    I tried this using the setTabOrder function, but
    @// it does not work
    setTabOrder(custom1, button);
    setTabOrder(button, custom2);@

    The custom widgets never actually get the focus, just their underlying LineEdits do. Is there a possibility to do this?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      The tab order inside the custom widget, is the business of the custom widget. I don't really get what the actual problem is here.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        broadpeak
        wrote on last edited by
        #3

        Probably you have to reimplement the QWidget::focusNextPrevChild method...

        1 Reply Last reply
        0
        • W Offline
          W Offline
          Wurstinator
          wrote on last edited by
          #4

          Andre:
          Ok, let me try to explain it again.
          This is the tab order I want to have: http://pbrd.co/OUVqRa
          However, if I use the code I showed in my start post or just specify no tab order at all, this is the tab order I get: http://pbrd.co/QaGNEw

          broadpeak:
          Wouldn't that be the same as setTabOrder? If I rewrite that method, I could do something like @custom2->setFocus(Qt::OtherFocusReason)@ but afaik you cannot just give the focus to those custom widgets. Only the LineEdits can have their focus set like this.

          [Edit: Removed extraneous @ tags which were messing up formatting. -- mlong]

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            So, what happens if you set the tab order in this form to be TopCustomWidget -> Button -> CenterCustomWidget, and then inside the custom widgets, to leftLineEdit -> rightLineEdit ?

            1 Reply Last reply
            0
            • W Offline
              W Offline
              Wurstinator
              wrote on last edited by
              #6

              That is what I did and which gives me the unwanted result.

              @CustomWidget::CustomWidget(QWidget *parent)
              : QWidget(parent)
              {
              lineedit1 = new QLineEdit;
              lineedit2 = new QLineEdit;
              layout = new QHBoxLayout;
              layout->addWidget(lineedit1);
              layout->addWidget(lineedit2);
              setLayout(layout);
              setTabOrder(lineedit1, lineedit2); // here
              }@

              @qtTEST::qtTEST(QWidget *parent, Qt::WFlags flags)
              : QMainWindow(parent, flags)
              {
              QVBoxLayout *layout = new QVBoxLayout;
              QWidget *wid = new QWidget;
              setCentralWidget(wid);
              wid->setLayout(layout);

              CustomWidget *top = new CustomWidget;
              CustomWidget *bot = new CustomWidget;
              layout->addWidget(top);
              layout->addWidget(bot);
              QPushButton *button = new QPushButton;
              layout->addWidget(button);

              wid->setTabOrder(top, button); // here
              wid->setTabOrder(button, bot); // and here
              }@

              1 Reply Last reply
              0
              • W Offline
                W Offline
                Wurstinator
                wrote on last edited by
                #7

                I made it work. The key is to call
                @setFocusProxy(x); // x is your first child widget
                setFocusPolicy(Qt::TabFocus);@
                inside the custom widget.

                It is important that you cannot simply use setTabOrder inside the custom widget to give its children a special order. You have to create those widgets in the wanted order.
                Example, if you want the right QLineEdit be focused first, then the left one:
                @lineedit2 = new QLineEdit(this);
                lineedit1 = new QLineEdit(this);@

                Maybe this might help someone, who has the same problem in the future.

                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