Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. displaying several treeviews one below the other
Forum Update on Monday, May 27th 2025

displaying several treeviews one below the other

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 3 Posters 332 Views
  • 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.
  • S Offline
    S Offline
    sof4Rou
    wrote on last edited by
    #1

    I have a project that consists in displaying a datamodel using qtreeview from a folder that contains several files. I displayed a treeview of a single file but i couldn't display several treeviews one under the other of several files.
    here is my main.py :

    import sys
    from PyQt5.QtWidgets import *
    from start_window import StartWindow
    
    def main():
        app = QApplication(sys.argv)
        start_window = StartWindow()
        start_window.show()
        sys.exit(app.exec_())
    
    if __name__ == '__main__':
        main()
    

    my start_window.py where I need to implement the choose folder function to reach the goal :

    from PyQt5.QtWidgets import *
    from PyQt5.QtCore import *
    from PyQt5.QtGui import *
    from table_view import Table
    from odl_parser import ODLParser
    
    class StartWindow(QDialog):
        def __init__(self, parent=None):
            super().__init__(parent)
            self.setWindowTitle('Open ODL File or Folder')
            self.resize(600, 400) 
    
            main_layout = QHBoxLayout(self)
    
            self.image_label = QLabel(self)
            self.image_label.setPixmap(QPixmap('ACLViewer.jpg').scaled(300, 300, Qt.KeepAspectRatio))
            main_layout.addWidget(self.image_label)
    
            buttons_layout = QVBoxLayout()
    
            self.choose_file_button = QPushButton('Choose File', self)
            self.choose_file_button.clicked.connect(self.choose_file)
            buttons_layout.addWidget(self.choose_file_button)
            
            self.choose_folder_button = QPushButton('Choose Folder', self)
            self.choose_folder_button.clicked.connect(self.choose_folder)
            buttons_layout.addWidget(self.choose_folder_button)
    
            main_layout.addLayout(buttons_layout)
    
        def choose_file(self):
            file_path, _ = QFileDialog.getOpenFileName(self, "Open ODL File", "", "ODL Files (*.odl)")
            if file_path:
                self.open_table_view(file_path)
    
        def choose_folder(self):
            folder_path = QFileDialog.getExistingDirectory(self, "Open Folder Containing ODL Files")
            if folder_path:
                # code for the folder
    
        def open_table_view(self, file_path):
            parser = ODLParser(file_path)
            window = Table(parser)
            window.setWindowTitle('DM Parsing - ' + file_path)
            window.show()
    

    Capture.PNG
    can anybody help me ?

    jsulmJ 1 Reply Last reply
    0
    • S sof4Rou

      I have a project that consists in displaying a datamodel using qtreeview from a folder that contains several files. I displayed a treeview of a single file but i couldn't display several treeviews one under the other of several files.
      here is my main.py :

      import sys
      from PyQt5.QtWidgets import *
      from start_window import StartWindow
      
      def main():
          app = QApplication(sys.argv)
          start_window = StartWindow()
          start_window.show()
          sys.exit(app.exec_())
      
      if __name__ == '__main__':
          main()
      

      my start_window.py where I need to implement the choose folder function to reach the goal :

      from PyQt5.QtWidgets import *
      from PyQt5.QtCore import *
      from PyQt5.QtGui import *
      from table_view import Table
      from odl_parser import ODLParser
      
      class StartWindow(QDialog):
          def __init__(self, parent=None):
              super().__init__(parent)
              self.setWindowTitle('Open ODL File or Folder')
              self.resize(600, 400) 
      
              main_layout = QHBoxLayout(self)
      
              self.image_label = QLabel(self)
              self.image_label.setPixmap(QPixmap('ACLViewer.jpg').scaled(300, 300, Qt.KeepAspectRatio))
              main_layout.addWidget(self.image_label)
      
              buttons_layout = QVBoxLayout()
      
              self.choose_file_button = QPushButton('Choose File', self)
              self.choose_file_button.clicked.connect(self.choose_file)
              buttons_layout.addWidget(self.choose_file_button)
              
              self.choose_folder_button = QPushButton('Choose Folder', self)
              self.choose_folder_button.clicked.connect(self.choose_folder)
              buttons_layout.addWidget(self.choose_folder_button)
      
              main_layout.addLayout(buttons_layout)
      
          def choose_file(self):
              file_path, _ = QFileDialog.getOpenFileName(self, "Open ODL File", "", "ODL Files (*.odl)")
              if file_path:
                  self.open_table_view(file_path)
      
          def choose_folder(self):
              folder_path = QFileDialog.getExistingDirectory(self, "Open Folder Containing ODL Files")
              if folder_path:
                  # code for the folder
      
          def open_table_view(self, file_path):
              parser = ODLParser(file_path)
              window = Table(parser)
              window.setWindowTitle('DM Parsing - ' + file_path)
              window.show()
      

      Capture.PNG
      can anybody help me ?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @sof4Rou said in displaying several treeviews one below the other:

      but i couldn't display several treeviews one under the other of several files

      And what is the problem? If you can add one QTreeView then you can also add more than one.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      JonBJ 1 Reply Last reply
      0
      • jsulmJ jsulm

        @sof4Rou said in displaying several treeviews one below the other:

        but i couldn't display several treeviews one under the other of several files

        And what is the problem? If you can add one QTreeView then you can also add more than one.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @jsulm
        I'm not sure, but I wonder whether @sof4Rou really means they want one treeview and have not understood that each row in the treeview is another (potentially-collapsible) node. That is what their picture looks like to me. @sof4Rou: why do you want multiple treeviews?

        S 1 Reply Last reply
        0
        • JonBJ JonB

          @jsulm
          I'm not sure, but I wonder whether @sof4Rou really means they want one treeview and have not understood that each row in the treeview is another (potentially-collapsible) node. That is what their picture looks like to me. @sof4Rou: why do you want multiple treeviews?

          S Offline
          S Offline
          sof4Rou
          wrote on last edited by
          #4

          @JonB I don't want one treeView , I have many files , each file has an output one treeView but now i have a folder which contain several files , so when i choose a folder i want to display all the treeview one under the other

          JonBJ 1 Reply Last reply
          0
          • S sof4Rou

            @JonB I don't want one treeView , I have many files , each file has an output one treeView but now i have a folder which contain several files , so when i choose a folder i want to display all the treeview one under the other

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @sof4Rou
            Then, as in any case where you want to create multiple widgets at runtime, you will have to create new QTreeViews dynamically (at runtime). And have somewhere to add them onto, like a QVBoxLayout.

            1 Reply Last reply
            1

            • Login

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