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

Examples with QtWidgets #610

Closed
hanusek opened this issue Jul 15, 2023 · 4 comments
Closed

Examples with QtWidgets #610

hanusek opened this issue Jul 15, 2023 · 4 comments

Comments

@hanusek
Copy link

hanusek commented Jul 15, 2023

Hello!
I am looking for examples of QtWidget (not QML/QtQuick). Where can I find it?

@hanusek hanusek changed the title Examples with QtWigets Examples with QtWidgets Jul 15, 2023
@Be-ing
Copy link
Contributor

Be-ing commented Jul 16, 2023

We haven't made those yet. Hopefully I'll get around to it in the next couple weeks.

Closing as a duplicate of #143.

@Be-ing Be-ing closed this as completed Jul 16, 2023
@ahayzen-kdab
Copy link
Collaborator

Note that exposing QObjects / list models from Rust -> a C++ widgets app is no different to using QML.

Driving widgets from Rust only should be simpler now we support normal CXX extern blocks. Just that a lot of the widgets API is pointer driven, so you either need to pass around raw pointers in Rust (which uses unsafe blocks) or have wrapper methods that convert these to/from UniquePtr/SharedPtr. Some of this could likely be templated though.

And I also am unsure about trying to add widgets API into cxx-qt-lib as that is a huge surface of API to support. I think instead having enough templated C++ methods that can be used or documented how to do it would be more useful.

@hanusek
Copy link
Author

hanusek commented Jul 17, 2023

@ahayzen-kdab
I expected CXX-Qt to be like PySide6 for Rust. Thanks for your reply.
https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/index.html

@ahayzen-kdab
Copy link
Collaborator

Note that it is very easy to expose C++ types through to Rust via CXX opaque type, eg if one wanted to use QPainter as a type in an invokable, and then wanted to use fillRect in the method it would just require the following CXX block.

    unsafe extern "C++" {
        type QPainter;
        include!(<QtGui/QPainter>);

        #[rust_name = "fill_rect"]
        fn fillRect(self: Pin<&mut QPainter>, rectangle: &QRectF, color: &QColor);
    }

However we are also evaluating which common types make sense for us to maintain in cxx-qt-lib to avoid boilerplate for the developer etc. Also note that other types have more things to gain from us providing types, as for types such as QString we are able to mark it as trivial for CXX rather than it being an opaque type (as QPainter is here below), whereas types like QPainter are likely not possible to be made trivial so there is a cost to benefit battle here.

I do think it's likely that we'll be adding more types and/or helpers for you to reach the types over time though, but we are also still evolving the main API.

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

No branches or pull requests

3 participants