Created
August 18, 2017 15:36
-
-
Save peteristhegreat/cbd8eaa0e565d0b82dbfb5c7fdc61c8d to your computer and use it in GitHub Desktop.
QTest QComboBox QListView click on each item in a combobox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Very helpful link: https://vicrucann.github.io/tutorials/qttest-signals-qtreewidget/ | |
// Select an item in the combobox list | |
QComboBox * cb = m_widget->findChild<QComboBox*>("testStandComboBox"); | |
QTest::mouseClick(cb, Qt::LeftButton); | |
QTest::qWait(1000); | |
QListView * lw = cb->findChild<QListView *>(); | |
if(lw) | |
{ | |
qDebug() << lw->size() << lw->gridSize();// << lw->count(); | |
for(int r = 0; r < lw->model()->rowCount(); r++) | |
{ | |
QModelIndex idx = lw->model()->index(r,0); | |
lw->scrollTo(idx); | |
QPoint itemPt = lw->visualRect(idx).center(); | |
QString str = lw->model()->index(r,0).data( Qt::DisplayRole ).toString(); | |
qDebug() << "clicking on" << str << itemPt; | |
// Click the combobox item | |
if(!itemPt.isNull()) | |
{ | |
QTest::mouseClick(lw->viewport(), Qt::LeftButton, 0, itemPt); | |
QTest::qWait(1000); | |
// Reopen the combobox | |
QTest::mouseClick(cb, Qt::LeftButton); | |
QTest::qWait(1000); | |
} | |
} | |
} | |
// Close the combo box popup | |
QTest::keyClick(cb, Qt::Key_Escape); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment