Open rdoreopto opened 7 years ago
Hi,
Yes no support for QTreeWidget at this time. Maybe it could be worked around by combining some click/tab events, bu t still a workaround. Proper support will require a bit of work. (If anyone wants to submit a pull request for this it will be welcome: check how support for QAction was added).
Regards,
Indeed, #50 is the best workaround I've found, because QTreeWidgetItem does not contain a real widget, it's all in the data member. I'm not sure how Qt renders the tree item on screen, but we don't have access to that (the only exception here is if a widget was specifically added with http://doc.qt.io/qt-4.8/qtreewidget.html#setItemWidget). It's the same thing with the QListWidget.
But, if a QListWidget or QTreeWidget does indeed contain one or more itemWidgets, then it would be easy to do this:
diff --git a/src/webdriver/extension_qt/widget_view_util.cc b/src/webdriver/extension_qt/widget_view_util.cc
index 7b234f2..5db6ef6 100644
--- a/src/webdriver/extension_qt/widget_view_util.cc
+++ b/src/webdriver/extension_qt/widget_view_util.cc
@@ -25,6 +25,14 @@
#include <QtCore/QMetaProperty>
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
+#include <QtWidgets/QListView>
+#include <QtWidgets/QListWidgetItem>
+#else
+#include <QtGui/QListView>
+#include <QtGui/QListWidgetItem>
+#endif
+
namespace webdriver {
const char QWidgetViewUtil::url_protocol[] = "qtwidget://";
@@ -126,6 +134,22 @@ void QWidgetXmlSerializer::addWidget(QObject* widget) {
writer_.writeEndElement();
}
+ QListWidget* listView = qobject_cast<QListWidget*>(pWidget);
+ // widget is a QListWidget*
+ if (NULL != listView) {
+ for (int i = 0; i < listView->count(); ++i) {
+ QListWidgetItem* listItem = listView->item(i);
+ QWidget * listItemWidget = listView->itemWidget(listItem);
+
+ if(!listItemWidget) {
+ // The item at this index is not an item widget, thus we skip it.
+ continue;
+ }
+
+ addWidget(listItemWidget);
+ }
+ }
+
// write child widgets
QList<QObject*> childs = pWidget->children();
foreach(QObject* child, childs) {
This is just an example for the QListWidget. For a QTreeWidget it would be pretty similar (although there would be some sort of tree traversal).
Qt version: 4.8.7 OS: Ubuntu 16.04 Xenial
Hello,
I'm using QtWebDriver to test a native application (the webdriver attaches to the running application). It has been working great so far, but I've encountered a little problem.
I have have widget which contains a QTreeWidget, here is the XML that QtWebDriver generates:
What I would like to do is click on an item in the QTreeWidget. Is it possible (or could it be made possible)?
Thank you very much!
Raphael