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. Pyside2 - How to create notes/comments and display them corresponding to selected item from list

Pyside2 - How to create notes/comments and display them corresponding to selected item from list

Scheduled Pinned Locked Moved Unsolved Qt for Python
pyside2pythonqt for python
12 Posts 5 Posters 1.1k 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.
  • Y Offline
    Y Offline
    younglegend
    wrote on last edited by younglegend
    #1

    I have been creating a tool that displays multiple file versions from a folder in a QListWidget.

    I would like to save notes/comments for each version and display them using QTextEdit corresponding to the item in the list that i click. Like a version manger. How shall i go about this? Kinda stuck... Thank you!

    import sys
    from PySide2 import QtCore, QtGui, QtWidgets
    
    
    class Dialog(QtWidgets.QDialog):
        NumList = 20
    
        def __init__(self):
            super(Dialog, self).__init__()
    
            self.createHorizontalGroupBox()
            self.createVerticalGroupBox()
            mainLayout = QtWidgets.QVBoxLayout()
            mainLayout.addWidget(self.verticalGroupBox)
            mainLayout.addWidget(self.horizontalGroupBox)
            self.setWindowTitle("File Manager v1.0")
            self.setLayout(mainLayout)
    
    
    
        def createVerticalGroupBox(self):
            self.verticalGroupBox = QtWidgets.QGroupBox("List Files")
            layout = QtWidgets.QVBoxLayout()
            layout.setContentsMargins(25,25,25,25)
            layout.setSpacing(7)
    
            file_listbox = QtWidgets.QListWidget()
            for i in range(Dialog.NumList):
                file_list = ("File_v%d" % (i+1))
                file_listbox.addItem(file_list)
            layout.addWidget(file_listbox)
    
            self.verticalGroupBox.setLayout(layout)
    
    
        def createHorizontalGroupBox(self):
            self.horizontalGroupBox = QtWidgets.QGroupBox("Notes")
            layoutB = QtWidgets.QGridLayout()
            layoutB.setContentsMargins(25, 25, 25, 25)
            layoutB.setSpacing(7)
            layoutB.setColumnStretch(0,5)
    
            self.notes_editor = QtWidgets.QTextEdit()
            self.notes_editor.setPlainText("Test..")
            layoutB.addWidget(self.notes_editor,0, 2, 4, 1)
    
            self.edit_button = QtWidgets.QPushButton("Edit..")
            layoutB.addWidget(self.edit_button,0,5)
    
            self.save_button = QtWidgets.QPushButton("Save")
            layoutB.addWidget(self.save_button,1,5)
    
            self.horizontalGroupBox.setLayout(layoutB)
    
    
    
    
    
    app = QtWidgets.QApplication(sys.argv)
    dialog = Dialog()
    sys.exit(dialog.exec_())
    
    JonBJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      How are you storing these different file versions ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Y 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        How are you storing these different file versions ?

        Y Offline
        Y Offline
        younglegend
        wrote on last edited by
        #3

        @SGaist Cheers!
        If i understood you right, i'm storing these versions as fileName_v001, fileName_v002 and so on...

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then this might come as a silly question but since there's VCS like git, are you sure you are using the tool ?

          Anyway, for your current system, you could have a second file following the name schema with a different extension for the notes. Or have them in a SQLite database.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          Y 1 Reply Last reply
          1
          • SGaistS SGaist

            Then this might come as a silly question but since there's VCS like git, are you sure you are using the tool ?

            Anyway, for your current system, you could have a second file following the name schema with a different extension for the notes. Or have them in a SQLite database.

            Y Offline
            Y Offline
            younglegend
            wrote on last edited by
            #5

            @SGaist That's where i'm stuck, i have no idea how to implement it with PySide. I like to manually type my tools using examples/forum guides as reference. But examples for vcs with Qt is something i never came across with google search. Which is surprising...

            jsulmJ 1 Reply Last reply
            0
            • Y younglegend

              @SGaist That's where i'm stuck, i have no idea how to implement it with PySide. I like to manually type my tools using examples/forum guides as reference. But examples for vcs with Qt is something i never came across with google search. Which is surprising...

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

              @younglegend said in Pyside2 - How to create notes/comments and display them corresponding to selected item from list:

              But examples for vcs with Qt is something i never came across with google search

              Well, it does not have anything to do with Qt actually. Qt is a C++ framework, so you write code using Qt as framework. In your case it's Python code, but this does not change anything. Just use a VCS as you could do with any project.

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

              1 Reply Last reply
              1
              • Y younglegend

                I have been creating a tool that displays multiple file versions from a folder in a QListWidget.

                I would like to save notes/comments for each version and display them using QTextEdit corresponding to the item in the list that i click. Like a version manger. How shall i go about this? Kinda stuck... Thank you!

                import sys
                from PySide2 import QtCore, QtGui, QtWidgets
                
                
                class Dialog(QtWidgets.QDialog):
                    NumList = 20
                
                    def __init__(self):
                        super(Dialog, self).__init__()
                
                        self.createHorizontalGroupBox()
                        self.createVerticalGroupBox()
                        mainLayout = QtWidgets.QVBoxLayout()
                        mainLayout.addWidget(self.verticalGroupBox)
                        mainLayout.addWidget(self.horizontalGroupBox)
                        self.setWindowTitle("File Manager v1.0")
                        self.setLayout(mainLayout)
                
                
                
                    def createVerticalGroupBox(self):
                        self.verticalGroupBox = QtWidgets.QGroupBox("List Files")
                        layout = QtWidgets.QVBoxLayout()
                        layout.setContentsMargins(25,25,25,25)
                        layout.setSpacing(7)
                
                        file_listbox = QtWidgets.QListWidget()
                        for i in range(Dialog.NumList):
                            file_list = ("File_v%d" % (i+1))
                            file_listbox.addItem(file_list)
                        layout.addWidget(file_listbox)
                
                        self.verticalGroupBox.setLayout(layout)
                
                
                    def createHorizontalGroupBox(self):
                        self.horizontalGroupBox = QtWidgets.QGroupBox("Notes")
                        layoutB = QtWidgets.QGridLayout()
                        layoutB.setContentsMargins(25, 25, 25, 25)
                        layoutB.setSpacing(7)
                        layoutB.setColumnStretch(0,5)
                
                        self.notes_editor = QtWidgets.QTextEdit()
                        self.notes_editor.setPlainText("Test..")
                        layoutB.addWidget(self.notes_editor,0, 2, 4, 1)
                
                        self.edit_button = QtWidgets.QPushButton("Edit..")
                        layoutB.addWidget(self.edit_button,0,5)
                
                        self.save_button = QtWidgets.QPushButton("Save")
                        layoutB.addWidget(self.save_button,1,5)
                
                        self.horizontalGroupBox.setLayout(layoutB)
                
                
                
                
                
                app = QtWidgets.QApplication(sys.argv)
                dialog = Dialog()
                sys.exit(dialog.exec_())
                
                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @younglegend
                I'm not suggesting it's a good idea to do it this way, but....

                If you do not want to go down the road of a VCS tool or a database or similar to hold your file versions and comments (which is a whole different ballgame), but instead stick to no more than the simple file handling you currently have, then:

                Your files seem to be named File_vnumber. So store your comments in similarly named files, so you can pair them against your file version files. Either e.g. File_Comment_vnumber, or create a sub-directory named e.g. Comments and store the corresponding comments in the same-named File_vnumber but in the Comments sub-directory....

                Y 1 Reply Last reply
                1
                • JonBJ JonB

                  @younglegend
                  I'm not suggesting it's a good idea to do it this way, but....

                  If you do not want to go down the road of a VCS tool or a database or similar to hold your file versions and comments (which is a whole different ballgame), but instead stick to no more than the simple file handling you currently have, then:

                  Your files seem to be named File_vnumber. So store your comments in similarly named files, so you can pair them against your file version files. Either e.g. File_Comment_vnumber, or create a sub-directory named e.g. Comments and store the corresponding comments in the same-named File_vnumber but in the Comments sub-directory....

                  Y Offline
                  Y Offline
                  younglegend
                  wrote on last edited by
                  #8

                  @JonB I would gladly avoid vcs as my tool is fairly simple. But the problem is, being a beginner myself i couldn't find a forum discussion regarding this topic or a similar example i could improvise on.

                  JonBJ 1 Reply Last reply
                  0
                  • Y younglegend

                    @JonB I would gladly avoid vcs as my tool is fairly simple. But the problem is, being a beginner myself i couldn't find a forum discussion regarding this topic or a similar example i could improvise on.

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

                    @younglegend
                    Which is why I have suggested a very simple solution for you just using similarly named files. Whether that's adequate for whatever you are producing only you know.

                    1 Reply Last reply
                    0
                    • Y Offline
                      Y Offline
                      younglegend
                      wrote on last edited by younglegend
                      #10

                      @Denni-0 Thanks for such a nice explanation Denni! It looks cleaner now. And yes, switching to pyside was pretty straight forward.

                      I actually had a very different kind of layout workflow before. Then i came across some examples that came with pyside packages folder which had everything i need. almost....

                      1 Reply Last reply
                      0
                      • Y Offline
                        Y Offline
                        younglegend
                        wrote on last edited by
                        #11

                        Bump..! Any help with this please? Still stuck at the same place with little to no progress..

                        JonBJ 1 Reply Last reply
                        0
                        • Y younglegend

                          Bump..! Any help with this please? Still stuck at the same place with little to no progress..

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

                          @younglegend
                          Help with what exactly? I thought you had copied Denni's stuff or whatever? I thought you were going to implemented what i suggested about keeping your comment in a "shadow" file for each file?

                          Just to be 100% clear again. If you want a "proper" program for managing file versions + comments, you don't want to write it yourself, you should use a VCS out there like git or github. If however you want to knock up something to learn Qt, you could follow my simple suggestion, or you could get (a lot) more involved by doing it via a database from Qt....

                          1 Reply Last reply
                          0

                          • Login

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