Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How test QTableView edition with QTest ?
Forum Updated to NodeBB v4.3 + New Features

How test QTableView edition with QTest ?

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alexis.hodiquet
    wrote on last edited by
    #1

    Hello,

    I would like to simulate edition of a cell of QTableView with QTest.

    I have tried different approach but without any success:

    qtableview->show(); // I think that in my unit test I should no need that, could you confirm ?

    QModelIndex modelIndex = qtableview->model()->index(1,1); //I have tested that modelIndex is valid and that I retrieved expected data

    /First try: set the currentIndex on modelIndex
    thinking that keyClicks on qtableview will work on selected element of the tableview
    /
    qtableview->setCurrentIndex(modelIndex );
    QTest::KeyClicks(qtableview,"Hello Word");
    QCOMPARE(qtableview->model()->index(1,1).data(), "Hello World"); // --> FAILED

    /Second approach
    Get the cell widget
    /
    QWidget * qwidget = qtableview->indexWidget( modelIndex );
    //--> No test since the qwidget is NULL... why ?

    /Third approach
    Get the cell widget through the delegate
    /
    QWidget * qwidget = qtableview->itemDelegate( modelIndex )->createEditor(qtableview, QStyleOptionViewItem, modelIndex );
    QTest::KeyClicks(qwidget ,"Hello Word");
    QCOMPARE(qtableview->model()->index(1,1).data(), "Hello World"); // --> FAILED


    I have also added in the three aproaches without any success
    QTest::mouseDClick(qtableview)
    QTest::KeyClicks(qtableview,"Hello Word");

    Thanks for your help.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved