What is the difference between Row and RowLayout?

Row is a Item Positioner. Positioner items are container items that manage the positions of items in a declarative user interface. RowLayout is part of Qt Quick Layouts. They manage both the positions and the sizes of items on a declarative user interface, and are well suited for resizable user interfaces. Your code with RowLayout … Read more

CMAKE_PREFIX_PATH doesn’t help CMake in finding Qt5

I installed the following missing packages: sudo apt-get install qtbase5-dev sudo apt-get install qtdeclarative5-dev Attaching any kind of prefix is not required now: CMakeList: :~/junk/qtquick_hello_cmake$ cat CMakeLists.txt cmake_minimum_required(VERSION 2.8.12) project(qtquick_hello_cmake) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) find_package(Qt5 COMPONENTS Quick Core REQUIRED) qt5_add_resources(RESOURCES qml.qrc) add_executable(${PROJECT_NAME} “main.cpp” “qml.qrc”) qt5_use_modules(${PROJECT_NAME} Quick Core) target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Quick) New output: :~/junk/qtquick_hello_cmake$ … Read more

What is the difference between QQmlApplicationEngine and QQuickView?

Headline: QQmlApplicationEngine is newer and more powerful than QQuickView. QQmlApplicationEngine exposes some central application functionality to QML, which QQuickView application would normally control from C++: Connecting Qt.quit() to QCoreApplication::quit() Automatically loads translation files from an i18n directory adjacent to the main QML file. Automatically sets an incubation controller if the scene contains a QQuickWindow. Automatically … Read more

Different delegates for QML ListView

I’ve had the same problem, the Qt documentation is providing a pretty good answer: http://doc.qt.io/qt-5/qml-qtquick-loader.html#using-a-loader-within-a-view-delegate The easiest solution is an inline Component with a Loader to set a source file: ListView { id: contactsView anchors.left: parent.left anchors.top: parent.top width: parent.width height: parent.height orientation: Qt.Vertical spacing: 10 model: contactsModel delegate: Component { Loader { source: switch(position) … Read more

How can I access my Window object properties from C++ while using QQmlApplicationEngine?

Turning my comment into a proper answer: this is usually done by two methods: Get the root object of your QML scene through a view if you use QQuickView or just the QQmlApplicationEngine directly. This next step can be omitted for root objects, but for “qml objects” in general, you will need to have the … Read more

Image rounded corners in QML

A built-in official solution exists as of Qt 5 thanks to the QtGraphicalEffects module and I’m quite surprised to find out that no one provided such a simple solution. If you are targeting Qt 6.x QtGraphicalEffects is unfortunately deprecated so jump to the second part of the answer which proposes a solution independent of QtGraphicalEffects. … Read more

How to access C++ enum from QML?

You can wrap the enum in a class which derives from QObject (and that you expose to QML): style.hpp : #ifndef STYLE_HPP #define STYLE_HPP #include <QtGlobal> #if QT_VERSION < QT_VERSION_CHECK(5,0,0) // Qt 4 #include <QDeclarativeEngine> #else // Qt 5 #include <QQmlEngine> #endif // Required derivation from QObject class StyleClass : public QObject { Q_OBJECT public: … Read more

tech