Am 09.06.2018 12:46 schrieb Dileep Sankhla <sankhla.dilee...@gmail.com>:
On Sat, Jun 9, 2018 at 1:43 AM Tobias Deiminger <haxti...@posteo.de> wrote:
Am 08.06.2018 18:57 schrieb Dileep Sankhla:
> Hello Tobias,
>
> I have succeeded in getting the QInputDialog to write a new note:
>
> QMetaObject::invokeMethod(part.m_pageView, "slotToggleAnnotator",
> Q_ARG( bool, true ));  // displayes the annotation toolbar
> QList<QToolButton *> toolbuttonList =
> part.m_pageView->findChildren<QToolButton *>(); // Get the list of all
> 10 annotation toolbuttons
>
> QToolButton* typewriterButton = toolbuttonList.at(9); // Get's
> typewriter toolbutton at 10th posiiton
>
> typewriterButton->click();  // clicks and selects the typewriter tool
>
> // Clicks on the viewport and a QInputDialog popups
> QTest::mouseMove(part.m_pageView->viewport(), QPoint(width * 0.5,
> height * 0.2));
> QTest::mouseClick(part.m_pageView->viewport(), Qt::LeftButton,
> Qt::NoModifier, QPoint(width * 0.5, height * 0.2));
>
> It popups a multiline QInputDialog annotation window and prompts for
> the note. I write any content, press OK and the test ends.
> My question is how to check if the popup window appears in the test as
> it doesn't have any parent widget? So I can't do findChildren on
> part.m_pageView to check for the QInputDialog.

QApplication::activeModalWidget [0], QApplication::topLevelWidgets [1]
and friends come to my mind to find the QInputDialog window. You can get
the current QApplication with the qApp macro at any scope.
Actually as soon as the QInputDialog window shows up, it blocks the main UI. Only after manually closing it, the next code to grab the pointer of QInputDialog executes which then gives me the null QWidget. In this case, is there any way to continue with the UI thread and grab the pointer to the dialog without manually interacting with it?

Yes, the dialog blocks the main event loop and spawns a local exec() instead. You need to schedule an event to get into it, like with a QTimer. There's a class CloseDialogHelper in parttest.cpp, may you have a look at it?

 

> And after checking for
> the QInputDialog, how to CANCEL the dialog in the test so that my test
> doesn't pause at user's input prompt? I just need an idea as I'm stuck
> here.

Once you've got a pointer to the dialog widget, I think you can invoke
QDialog::done [2] to finish text input and continue annotation creation,
or QWidget::close [3] to just close it.

Had no time to look into the other issues in this thread yet, sorry.
Will answer later unless someone other does.

Cheers
Tobias

[0] http://doc.qt.io/qt-5/qapplication.html#activeModalWidget
[1] http://doc.qt.io/qt-5/qapplication.html#topLevelWidgets
[2] http://doc.qt.io/qt-5/qdialog.html#done
[3] http://doc.qt.io/qt-5/qwidget.html#close

Reply via email to