Moving selection from QPushButton to top object in QScrollArea does not move the view to the selected object.
-
I have set up a ScrollArea, with options spaced, expanding vertically. At the bottom there is a button. When there is enough options to cause the window to be scrollable, tabbing to select objects going from the button to the top object in the scrollArea, does not move the visible view to show the selected object, it only moves if the tabbing is done between objects in the scrollArea.
Here is a dummy code for how it is setup.
Dummy_func(qt::QtAreaInfo* area, QWidget* parent) : QWidget(parent) , _area(area) { setFocusPolicy(Qt::NoFocus); auto layout = new QVBoxLayout; setLayout(layout); _wid= new QWidget; _wid->setContentsMargins({}); _wid->setFocusPolicy(Qt::NoFocus); _wid->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); _widLayout = new QVBoxLayout; _widLayout->setContentsMargins({}); _wid->setLayout(_widLayout); _widLayout = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding); _filterAreaLayout->addSpacerItem(_widAreaStretch); auto scrollArea = new QScrollArea(); scrollArea->setContentsMargins({}); scrollArea->setWidget(_wid); scrollArea->setWidgetResizable(true); scrollArea->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); scrollArea->setFrameShape(QFrame::NoFrame); scrollArea->setFocusPolicy(Qt::NoFocus); scrollArea->setVerticalScrollBar(new FramedScrollBar(scrollArea)); layout->addWidget(scrollArea); scrollArea->verticalScrollBar()->installEventFilter(this); layout->addStretch(); auto buttonLayout = new QHBoxLayout; buttonLayout->addStretch(); layout->addLayout(buttonLayout); auto but = new QPushButton("test"); buttonLayout->addWidget(but); }
-
Hi and welcome to devnet,
Which version of Qt ?
On which OS ?
Also please provide a complete, minimal, buildable example. Your code as is, cannot be built. -
Hi,
Sorry for the late reply. Yes it's all good. One thing I didn't notice originally. You are disabling focus policies on all your widgets so how do you expect keyboard navigation to function ?
-
I have been testing around with setting tabFocus on the different widgets with different configurations, but with no difference in outcome. In the example provided keyboard navigation does work, it just does not focus when going from the button to the top item. Perhaps I am using the focus policies wrong, but I could not set it in a way that allowed the desired behaviour.