QTabWidget/Bar: ignore hidden tabs for key events
Even a tab was hidden it could be accessed with the key navigation or a scroll event which lead to painting artifacts. Pick-to: 6.5 5.15 Fixes: QTBUG-101219 Task-number: QTBUG-63038 Change-Id: I58be694eef5f86cccecbe528891a39a4acdda15f Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> (cherry picked from commit 83e92e25573f98e7530a3dfcaf02910f3932107f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
35da0bb56e
commit
b4384dab06
@ -2436,7 +2436,7 @@ void QTabBarPrivate::setCurrentNextEnabledIndex(int offset)
|
|||||||
{
|
{
|
||||||
Q_Q(QTabBar);
|
Q_Q(QTabBar);
|
||||||
for (int index = currentIndex + offset; validIndex(index); index += offset) {
|
for (int index = currentIndex + offset; validIndex(index); index += offset) {
|
||||||
if (tabList.at(index)->enabled) {
|
if (tabList.at(index)->enabled && tabList.at(index)->visible) {
|
||||||
q->setCurrentIndex(index);
|
q->setCurrentIndex(index);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1139,7 +1139,7 @@ void QTabWidget::keyPressEvent(QKeyEvent *e)
|
|||||||
) {
|
) {
|
||||||
page = 0;
|
page = 0;
|
||||||
}
|
}
|
||||||
if (d->tabs->isTabEnabled(page)) {
|
if (d->tabs->isTabEnabled(page) && d->tabs->isTabVisible(page)) {
|
||||||
setCurrentIndex(page);
|
setCurrentIndex(page);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ private slots:
|
|||||||
void hideTab_data();
|
void hideTab_data();
|
||||||
void hideTab();
|
void hideTab();
|
||||||
void hideAllTabs();
|
void hideAllTabs();
|
||||||
|
void checkHiddenTab();
|
||||||
|
|
||||||
void setElideMode_data();
|
void setElideMode_data();
|
||||||
void setElideMode();
|
void setElideMode();
|
||||||
@ -367,6 +368,25 @@ void tst_QTabBar::hideAllTabs()
|
|||||||
QVERIFY(sizeHint.width() < prevSizeHint.width());
|
QVERIFY(sizeHint.width() < prevSizeHint.width());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QTabBar::checkHiddenTab()
|
||||||
|
{
|
||||||
|
QTabBar tabbar;
|
||||||
|
|
||||||
|
tabbar.addTab("foo");
|
||||||
|
tabbar.addTab("bar");
|
||||||
|
tabbar.addTab("baz");
|
||||||
|
tabbar.setCurrentIndex(0);
|
||||||
|
tabbar.setTabVisible(1, false);
|
||||||
|
|
||||||
|
QKeyEvent keyRight(QKeyEvent::KeyPress, Qt::Key_Right, Qt::NoModifier);
|
||||||
|
QVERIFY(QApplication::sendEvent(&tabbar, &keyRight));
|
||||||
|
QCOMPARE(tabbar.currentIndex(), 2);
|
||||||
|
|
||||||
|
QKeyEvent keyLeft(QKeyEvent::KeyPress, Qt::Key_Left, Qt::NoModifier);
|
||||||
|
QVERIFY(QApplication::sendEvent(&tabbar, &keyLeft));
|
||||||
|
QCOMPARE(tabbar.currentIndex(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QTabBar::setElideMode_data()
|
void tst_QTabBar::setElideMode_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<int>("tabElideMode");
|
QTest::addColumn<int>("tabElideMode");
|
||||||
|
@ -60,6 +60,7 @@ private slots:
|
|||||||
void tabPosition();
|
void tabPosition();
|
||||||
void tabEnabled();
|
void tabEnabled();
|
||||||
void tabHidden();
|
void tabHidden();
|
||||||
|
void checkHiddenTab();
|
||||||
void tabText();
|
void tabText();
|
||||||
void tabShape();
|
void tabShape();
|
||||||
void tabTooltip();
|
void tabTooltip();
|
||||||
@ -252,6 +253,32 @@ void tst_QTabWidget::tabHidden()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QTabWidget::checkHiddenTab()
|
||||||
|
{
|
||||||
|
tw->addTab(new QWidget(), "foo");
|
||||||
|
tw->addTab(new QWidget(), "bar");
|
||||||
|
tw->addTab(new QWidget(), "baz");
|
||||||
|
QCOMPARE(tw->count(), 3);
|
||||||
|
tw->setCurrentIndex(0);
|
||||||
|
tw->setTabVisible(1, false);
|
||||||
|
|
||||||
|
QKeyEvent keyTab(QKeyEvent::KeyPress, Qt::Key_Tab, Qt::ControlModifier);
|
||||||
|
QVERIFY(QApplication::sendEvent(tw, &keyTab));
|
||||||
|
QCOMPARE(tw->currentIndex(), 2);
|
||||||
|
QVERIFY(QApplication::sendEvent(tw, &keyTab));
|
||||||
|
QCOMPARE(tw->currentIndex(), 0);
|
||||||
|
QVERIFY(QApplication::sendEvent(tw, &keyTab));
|
||||||
|
QCOMPARE(tw->currentIndex(), 2);
|
||||||
|
|
||||||
|
QKeyEvent keyBacktab(QKeyEvent::KeyPress, Qt::Key_Backtab, Qt::ControlModifier);
|
||||||
|
QVERIFY(QApplication::sendEvent(tw, &keyBacktab));
|
||||||
|
QCOMPARE(tw->currentIndex(), 0);
|
||||||
|
QVERIFY(QApplication::sendEvent(tw, &keyBacktab));
|
||||||
|
QCOMPARE(tw->currentIndex(), 2);
|
||||||
|
QVERIFY(QApplication::sendEvent(tw, &keyBacktab));
|
||||||
|
QCOMPARE(tw->currentIndex(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QTabWidget::tabText()
|
void tst_QTabWidget::tabText()
|
||||||
{
|
{
|
||||||
// Test bad arguments
|
// Test bad arguments
|
||||||
|
Loading…
x
Reference in New Issue
Block a user