TreeView in Qt5?
-
Hey, I know Qt just really added a TreeView in Qt 6.3, but I am stuck in Qt5 and need to use one in my QML Application.
What is my best bet here? Is there any official TreeView which is actually working decently? (I am using Qt 5.15.8, CMake and a GPL3 License)Thanks for any help in advance
-
I managed to do it by using
add_custom_target
to invoke qmake from my cmake file.
My cmake file now looks like this:cmake_minimum_required(VERSION 3.20) project(TreeViewTest VERSION 1.0 LANGUAGES CXX) # Configuration set(TREE_VIEW_OUTPUT ${PROJECT_BINARY_DIR}/qt_tree_view/qml/QtQuick/TreeView) set(QML_IMPORT_PATH ${TREE_VIEW_OUTPUT} CACHE STRING "Qml modules") # Qt set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) # Dependencies find_package(QT NAMES Qt5 COMPONENTS Quick Widgets QuickControls2 REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Quick Widgets QuickControls2 REQUIRED) # Build add_executable(appTreeViewTest src/sources.qrc src/main.cpp ) # Add treeview add_custom_target(qt_treeview_qmake ALL BYPRODUCTS ${TREE_VIEW_OUTPUT}/libqquicktreeviewplugin.so COMMAND mkdir -p qt_tree_view COMMAND qmake -o qt_tree_view ${PROJECT_SOURCE_DIR}/libs/qttreeview COMMAND make -C ${PROJECT_BINARY_DIR}/qt_tree_view VERBATIM USES_TERMINAL ) # Make treeViewTest depend on qt_treeview_qmake add_dependencies(appTreeViewTest qt_treeview_qmake) message(${PROJECT_BINARY_DIR}/qml/QtQuick/TreeView) # Link target_link_libraries(appTreeViewTest PRIVATE Qt5::Quick Qt5::Widgets Qt5::QuickControls2 ${TREE_VIEW_OUTPUT}/libqquicktreeviewplugin.so )
It surely can be improved, but this is the raw fix I came up with.
-
Hey, I know Qt just really added a TreeView in Qt 6.3, but I am stuck in Qt5 and need to use one in my QML Application.
What is my best bet here? Is there any official TreeView which is actually working decently? (I am using Qt 5.15.8, CMake and a GPL3 License)Thanks for any help in advance
@Creaperdown hey, someday in the past Qt company made the qml tree view module free instead of a yearly subsription!
yeahhhh
so take a look here:
https://marketplace.qt.io/collections/most-popular/products/treeview -
@Creaperdown hey, someday in the past Qt company made the qml tree view module free instead of a yearly subsription!
yeahhhh
so take a look here:
https://marketplace.qt.io/collections/most-popular/products/treeview@J-Hilk Hey, thanks for the link! I think I came across this once but had severe problems getting it to build with CMake. Is it compatible with CMake, or am I forced into using qmkae with it?
-
@J-Hilk Hey, thanks for the link! I think I came across this once but had severe problems getting it to build with CMake. Is it compatible with CMake, or am I forced into using qmkae with it?
@Creaperdown the git repo has a cmakelist and a pro file, sp both ?
Im not sure, haven't used it myself yet
-
@Creaperdown the git repo has a cmakelist and a pro file, sp both ?
Im not sure, haven't used it myself yet
@J-Hilk It does, but in the README.md it says:
"NOTE: If you use Qt 6, you can also build with cmake. But if you're using a Qt version
below Qt 6.2, you need to do "git checkout 6.1" before building."Might there be a way around this? How would I be able to use this in my Cmake project? Or if I cant build it with cmake, can I at least somehow use a qmake sub-project in my cmake project?
-
@J-Hilk It does, but in the README.md it says:
"NOTE: If you use Qt 6, you can also build with cmake. But if you're using a Qt version
below Qt 6.2, you need to do "git checkout 6.1" before building."Might there be a way around this? How would I be able to use this in my Cmake project? Or if I cant build it with cmake, can I at least somehow use a qmake sub-project in my cmake project?
@Creaperdown someone else might be able to help you here more, sry
AFAIK you can not simply mix cmake and qmake, in your project
What I see is that if you translate this pro file to a cmake file, you should be able to use it?
https://code.qt.io/cgit/qt-extensions/qttreeview.git/tree/src/src.pro -
@Creaperdown someone else might be able to help you here more, sry
AFAIK you can not simply mix cmake and qmake, in your project
What I see is that if you translate this pro file to a cmake file, you should be able to use it?
https://code.qt.io/cgit/qt-extensions/qttreeview.git/tree/src/src.pro@J-Hilk I have no experience with qmake, how would I translate this to cmake? Is there a command I need to run on it or should I manually do it?
-
@J-Hilk Hey, thanks for the link! I think I came across this once but had severe problems getting it to build with CMake. Is it compatible with CMake, or am I forced into using qmkae with it?
@Creaperdown said in TreeView in Qt5?:
Is it compatible with CMake, or am I forced into using qmkae with it?
In Qt 6, Qt modules are built with CMake. In Qt 5, they are built with qmake.
Use qmake to build and install it into your Qt folder (
qmake && make && make install
). After this, you should be able to use it in your CMake project. -
@Creaperdown said in TreeView in Qt5?:
Is it compatible with CMake, or am I forced into using qmkae with it?
In Qt 6, Qt modules are built with CMake. In Qt 5, they are built with qmake.
Use qmake to build and install it into your Qt folder (
qmake && make && make install
). After this, you should be able to use it in your CMake project.@JKSH My cmake Project is an open source application hosted on github, I cant just compile it and use the local copy. I'd need a solution which integrates with my build process
-
@JKSH My cmake Project is an open source application hosted on github, I cant just compile it and use the local copy. I'd need a solution which integrates with my build process
@Creaperdown said in TreeView in Qt5?:
My cmake Project is an open source application hosted on github, I cant just compile it and use the local copy. I'd need a solution which integrates with my build process
I see. I'm afraid I don't have the knowledge to help you with direct CMake integration.
-
@Creaperdown said in TreeView in Qt5?:
My cmake Project is an open source application hosted on github, I cant just compile it and use the local copy. I'd need a solution which integrates with my build process
I see. I'm afraid I don't have the knowledge to help you with direct CMake integration.
@JKSH Thanks for trying anyways. Do you have an idea on how I could proceed from here? I cant seem to find a solution to this and so far I reaching out for help didn't work out. Is my best option to just wait?
-
@JKSH Thanks for trying anyways. Do you have an idea on how I could proceed from here? I cant seem to find a solution to this and so far I reaching out for help didn't work out. Is my best option to just wait?
@Creaperdown said in TreeView in Qt5?:
@JKSH Thanks for trying anyways. Do you have an idea on how I could proceed from here? I cant seem to find a solution to this and so far I reaching out for help didn't work out. Is my best option to just wait?
You're welcome.
You could try posting a feature request at https://bugreports.qt.io/ and see if The Qt Company would provide CMake build files for Qt 5.
Alternatively, would it be feasible for you to build the module, host the built artifacts in a public place (say, https://cloudsmith.com/ -- they have a generous free tier for open-source projects) and use those in your build process?
-
@Creaperdown said in TreeView in Qt5?:
@JKSH Thanks for trying anyways. Do you have an idea on how I could proceed from here? I cant seem to find a solution to this and so far I reaching out for help didn't work out. Is my best option to just wait?
You're welcome.
You could try posting a feature request at https://bugreports.qt.io/ and see if The Qt Company would provide CMake build files for Qt 5.
Alternatively, would it be feasible for you to build the module, host the built artifacts in a public place (say, https://cloudsmith.com/ -- they have a generous free tier for open-source projects) and use those in your build process?
@JKSH I'll submit the feature request, but I suppose this could take quiet a long time to be added, if it will added in the first place.
The way of pre-building it and fetching the binaries from a cloud seems very cumbersome and fragile, I'd prefer not to use this if possible.
Wouldn't it be a better option to fall back on a non-official TreeView (e.g. something like this: https://github.com/ColinDuquesnoy/QtQuickControls2.TreeView) at this point?
-
I managed to do it by using
add_custom_target
to invoke qmake from my cmake file.
My cmake file now looks like this:cmake_minimum_required(VERSION 3.20) project(TreeViewTest VERSION 1.0 LANGUAGES CXX) # Configuration set(TREE_VIEW_OUTPUT ${PROJECT_BINARY_DIR}/qt_tree_view/qml/QtQuick/TreeView) set(QML_IMPORT_PATH ${TREE_VIEW_OUTPUT} CACHE STRING "Qml modules") # Qt set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) # Dependencies find_package(QT NAMES Qt5 COMPONENTS Quick Widgets QuickControls2 REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Quick Widgets QuickControls2 REQUIRED) # Build add_executable(appTreeViewTest src/sources.qrc src/main.cpp ) # Add treeview add_custom_target(qt_treeview_qmake ALL BYPRODUCTS ${TREE_VIEW_OUTPUT}/libqquicktreeviewplugin.so COMMAND mkdir -p qt_tree_view COMMAND qmake -o qt_tree_view ${PROJECT_SOURCE_DIR}/libs/qttreeview COMMAND make -C ${PROJECT_BINARY_DIR}/qt_tree_view VERBATIM USES_TERMINAL ) # Make treeViewTest depend on qt_treeview_qmake add_dependencies(appTreeViewTest qt_treeview_qmake) message(${PROJECT_BINARY_DIR}/qml/QtQuick/TreeView) # Link target_link_libraries(appTreeViewTest PRIVATE Qt5::Quick Qt5::Widgets Qt5::QuickControls2 ${TREE_VIEW_OUTPUT}/libqquicktreeviewplugin.so )
It surely can be improved, but this is the raw fix I came up with.
-