look at this window example: http://pbrd.co/QEHdDP
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
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
custom widget center
I tried this using the setTabOrder function, but
@// it does not work
The custom widgets never actually get the focus, just their underlying LineEdits do. Is there a possibility to do this?
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.
Probably you have to reimplement the QWidget::focusNextPrevChild method...
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
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]
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 ?
That is what I did and which gives me the unwanted result.
lineedit1 = new QLineEdit;
lineedit2 = new QLineEdit;
layout = new QHBoxLayout;
setTabOrder(lineedit1, lineedit2); // here
@qtTEST::qtTEST(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
QVBoxLayout *layout = new QVBoxLayout;
QWidget *wid = new QWidget;
CustomWidget *top = new CustomWidget;
CustomWidget *bot = new CustomWidget;
QPushButton *button = new QPushButton;
wid->setTabOrder(top, button); // here
wid->setTabOrder(button, bot); // and here
I made it work. The key is to call
@setFocusProxy(x); // x is your first child widget
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.