0

I have two checkboxes (QCheckbox), the first of which I sometimes hide. After calling hide() I then want to retrieve the nextInFocusChain() for the parent widget. This returns the first checkbox, regardless of whether it's hidden or not. Am I doing something wrong? I would have thought that a hidden widget isn't part of the focus chain, so it shouldn't be returned.

if (shouldHideFirstCheckbox) {
    firstCheckbox.hide();
}
QCheckBox* nextWidget = dynamic_cast<QCheckBox*>(nextInFocusChain());
// nextWidget is always firstCheckbox, regardless of whether it's hidden

1 Answer 1

1

Short answer: it's by design.

If you look at the implementation of QWidget::setTabOrder(), you'll see that widget's visibility isn't taken into account: https://code.woboq.org/qt5/qtbase/src/widgets/kernel/qwidget.cpp.html#6969

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.