Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. TreeView in Qt5?
Forum Updated to NodeBB v4.3 + New Features

TreeView in Qt5?

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 3 Posters 1.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Creaperdown
    wrote on last edited by
    #1

    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

    J.HilkJ 1 Reply Last reply
    0
    • C Offline
      C Offline
      Creaperdown
      wrote on last edited by
      #14

      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.

      1 Reply Last reply
      1
      • C Creaperdown

        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

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #2

        @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


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        C 1 Reply Last reply
        0
        • J.HilkJ J.Hilk

          @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

          C Offline
          C Offline
          Creaperdown
          wrote on last edited by Creaperdown
          #3

          @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.HilkJ JKSHJ 2 Replies Last reply
          0
          • C Creaperdown

            @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.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #4

            @Creaperdown the git repo has a cmakelist and a pro file, sp both ?

            Im not sure, haven't used it myself yet


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            C 1 Reply Last reply
            0
            • J.HilkJ J.Hilk

              @Creaperdown the git repo has a cmakelist and a pro file, sp both ?

              Im not sure, haven't used it myself yet

              C Offline
              C Offline
              Creaperdown
              wrote on last edited by
              #5

              @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.HilkJ 1 Reply Last reply
              0
              • C Creaperdown

                @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.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #6

                @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


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                C 1 Reply Last reply
                0
                • J.HilkJ J.Hilk

                  @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

                  C Offline
                  C Offline
                  Creaperdown
                  wrote on last edited by Creaperdown
                  #7

                  @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?

                  1 Reply Last reply
                  0
                  • C Creaperdown

                    @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?

                    JKSHJ Offline
                    JKSHJ Offline
                    JKSH
                    Moderators
                    wrote on last edited by
                    #8

                    @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.

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    C 1 Reply Last reply
                    0
                    • JKSHJ JKSH

                      @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.

                      C Offline
                      C Offline
                      Creaperdown
                      wrote on last edited by
                      #9

                      @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

                      JKSHJ 1 Reply Last reply
                      0
                      • C Creaperdown

                        @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

                        JKSHJ Offline
                        JKSHJ Offline
                        JKSH
                        Moderators
                        wrote on last edited by
                        #10

                        @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.

                        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                        C 1 Reply Last reply
                        0
                        • JKSHJ JKSH

                          @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.

                          C Offline
                          C Offline
                          Creaperdown
                          wrote on last edited by
                          #11

                          @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?

                          JKSHJ 1 Reply Last reply
                          0
                          • C Creaperdown

                            @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?

                            JKSHJ Offline
                            JKSHJ Offline
                            JKSH
                            Moderators
                            wrote on last edited by
                            #12

                            @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?

                            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                            C 1 Reply Last reply
                            0
                            • JKSHJ JKSH

                              @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?

                              C Offline
                              C Offline
                              Creaperdown
                              wrote on last edited by
                              #13

                              @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?

                              1 Reply Last reply
                              0
                              • C Offline
                                C Offline
                                Creaperdown
                                wrote on last edited by
                                #14

                                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.

                                1 Reply Last reply
                                1
                                • C Creaperdown has marked this topic as solved on

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved