How to set application icon #1319
-
Disclaimer: I'm a newbie in both Rust and Qt and started a toy project to learn both. In all examples about QT it states that setting an icon is just invoking a method on application object: app.setWindowIcon(QIcon(":/path/to/icon.png")); But I'm struggling to understand how to implement similar via rust/cxx-qt: I don't see that method on QApplication type and don't understand how to import QIcon into Rust. Could somebody provide an example of how to do that 🙏🏻 ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
At the moment there is no existing binding around As a workaround you could write a C++ method like void appSetWindowIcon(const QString& path) {
Q_ASSERT(qGuiApp != nullptr);
qGuiApp->setWindowIcon(QIcon(path));
} Then use a normal CXX C++ bridge to use that ...
unsafe extern "C++" {
include!("path/to/cpp/header.h");
fn appSetWindowIcon(path: &QString);
}
... A lot of the time if you are missing things, either it means writing bindings yourself, reusing extern C++Qt blocks where possible, or writing a C++ method that takes simpler types that already have bindings. |
Beta Was this translation helpful? Give feedback.
-
It took more efforts, but worked. Thanks! |
Beta Was this translation helpful? Give feedback.
At the moment there is no existing binding around
QIcon
, once that exists then QApplication and/or QGuiApplication could add setWindowIcon.As a workaround you could write a C++ method like
Then use a normal CXX C++ bridge to use that
A lot of the time if you are missing things, either it means writing bindings yourself, reusing extern C++Qt blocks where possible, or writing a C++ method that takes simpler types that already have bindings.