Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QQuickWidget support #8

Open
ov opened this issue Dec 7, 2019 · 4 comments
Open

QQuickWidget support #8

ov opened this issue Dec 7, 2019 · 4 comments
Labels
enhancement New feature or request

Comments

@ov
Copy link

ov commented Dec 7, 2019

Do you guys consider adding support for qml running in widgets? We use QMainWindow with QQuickWidget as a central widget for a couple of reasons and so far Spix cannot automate such applications.

After some digging I ended up with a working version with just a few lines of code, so maybe you can add that? You will need to add Qt5::Widgets and Qt5::QuickWidgets to the project, then add a widget-searching function:

QQuickItem* getQuickWidgetItemAtPath(const spix::ItemPath& path)
{
	QList<QQuickItem *> list;
	auto windows = qApp->topLevelWidgets();
	for (const auto& window : windows) {
		auto qwidgets = window->findChildren<QQuickWidget *>();
		for (auto qw : qwidgets) {
			list << qobject_cast<QQuickWidget *>(qw)->rootObject();
		}
	}

	for (auto qi : list) {
		auto res = getQQuickItemWithRoot(path, qi);
		if (res) return res;
	}

	return nullptr;
}

that you call in QQuickItem* getQQuickItemAtPath(const spix::ItemPath& path) in its "nothing found" branch:

if (!itemWindow) {
        return getQuickWidgetItemAtPath(path);
}

finally, it needs two includes at the top:

#include <QQuickWidget>
#include <QApplication>

as you would probably make widget support optional, I am not sure if I can submit a proper pull request that takes this into account, but you are very welcome to add the code above to the project, so I can use the original version.

Thank you :)

@faaxm faaxm added the enhancement New feature or request label Feb 20, 2020
@faaxm faaxm self-assigned this May 28, 2020
@faaxm faaxm removed their assignment Sep 13, 2020
@Laxx18
Copy link

Laxx18 commented Jan 17, 2022

Hi,

In your solution. I found an issue, so that the quickitem is never found. It must be:

auto res = getQQuickItemWithRoot(path.SubPath(1), qi);

instead of:
'auto res = getQQuickItemWithRoot(path, qi);'

It would be great, if all this code, could be merged from the maintainers into spix!

Best Regards
Laxx18

@faaxm
Copy link
Owner

faaxm commented Jan 17, 2022

I am generally open to seeing a pull request for this. However there are two things that might make this a bit more complicated than just copy pasting this code over:

  • Not everyone who uses spix will want to link to Qt5::Widgets, thus there would have to be a way to enabled this optionally. Probably with some cmake and compile flags. Something similar is already planned to support Qt6 (i.e. a flag to select which version of qt to link to), so finding a solution flexible enough to support both cases would be nice.
  • There would need to be an example in the spix examples folder showing the basic usage of spix with a widgets based app. It could be just the basic example wrapped in a QMainWindow.

@J-PREZORS
Copy link

J-PREZORS commented Oct 25, 2024

I would also like to see Spix support for GUI projects using widgets instead of QML (e.g. no QML at all).

I'm less concerned with sending QEvents ... my use case for testing is to be able to get widget properties for testing purposes in an ecosystem much simpler than the full-blown commercial alternatives (for complexity reasons).

e.g. what size is the widget? what coordinates is the widget? what displayed text does the widget have? exists?

Perhaps access to QApplication::allWidgets inside the AUT would allow such access.

Should this be a separate feature request?

@faaxm
Copy link
Owner

faaxm commented Oct 29, 2024

@J-PREZORS It's ok to keep it here and not as a separate feature request. In general Spix is designed to support any kind of GUI framework by implementing different "Scene" objects. I hope I find some time to write some docs about its design which would hopefully make extending it easier...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants