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. Generate tablewidget name on selecting range
Forum Updated to NodeBB v4.3 + New Features

Generate tablewidget name on selecting range

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 2 Posters 2.3k Views 1 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.
  • P Offline
    P Offline
    Piyush
    wrote on last edited by Piyush
    #1

    Hi,

    I need to generate tablewidget name on selecting range inside the tablewidget. Currently it works while i select a single cell, but when I select a range of cells, then it does not provide the table name. Code snippet shared:

    self.ui.table1.cellClicked.connect(self.get_obj_name)
    
    def get_obj_name(self, row, col):
            abc= self.sender()
            table = abc.objectName()
            self.table123 = "self.ui." + table
            self.table123 = QTableWidget()
    
    jsulmJ 1 Reply Last reply
    0
    • P Piyush

      Hi,

      I need to generate tablewidget name on selecting range inside the tablewidget. Currently it works while i select a single cell, but when I select a range of cells, then it does not provide the table name. Code snippet shared:

      self.ui.table1.cellClicked.connect(self.get_obj_name)
      
      def get_obj_name(self, row, col):
              abc= self.sender()
              table = abc.objectName()
              self.table123 = "self.ui." + table
              self.table123 = QTableWidget()
      
      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Piyush What is the use case? Why do you need to generate object name like this? Sounds quite unusual...
      And also: you're actually not generating object name but variable name (at least you try)!
      This, somehow, does not make sense:

      self.table123 = "self.ui." + table
      self.table123 = QTableWidget()
      

      First you assign a string and then a QTableWidget instance. So, the result will be that self.table123 will contain a QTableWidget() instance, doesn't matter what you selected.
      Is it possible that you actually want to use http://doc.qt.io/qt-5/qobject.html#objectName-prop?

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

      P 2 Replies Last reply
      0
      • jsulmJ jsulm

        @Piyush What is the use case? Why do you need to generate object name like this? Sounds quite unusual...
        And also: you're actually not generating object name but variable name (at least you try)!
        This, somehow, does not make sense:

        self.table123 = "self.ui." + table
        self.table123 = QTableWidget()
        

        First you assign a string and then a QTableWidget instance. So, the result will be that self.table123 will contain a QTableWidget() instance, doesn't matter what you selected.
        Is it possible that you actually want to use http://doc.qt.io/qt-5/qobject.html#objectName-prop?

        P Offline
        P Offline
        Piyush
        wrote on last edited by
        #3

        @jsulm I am trying to generate signal for retrieving object name for a generic copy function, which would work on any tablewidget, whenever we select a range. So, when we select multiples cells/range in a tablewidget it will copy the selected area.

        Please do not focus on the string part. The real question is how we can get the object name when we select a range within tablewidget.

        jsulmJ 1 Reply Last reply
        0
        • P Piyush

          @jsulm I am trying to generate signal for retrieving object name for a generic copy function, which would work on any tablewidget, whenever we select a range. So, when we select multiples cells/range in a tablewidget it will copy the selected area.

          Please do not focus on the string part. The real question is how we can get the object name when we select a range within tablewidget.

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Piyush Isn't sender() what you need? It returns you the object which emitted the signal (selection in this case).

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

          P 1 Reply Last reply
          2
          • jsulmJ jsulm

            @Piyush Isn't sender() what you need? It returns you the object which emitted the signal (selection in this case).

            P Offline
            P Offline
            Piyush
            wrote on last edited by
            #5

            @jsulm sender() provides the object name when we select a single cell withing the object. However, in my case I need to select a range of cells. So, sender() is not providing any signal if I select a range.

            I guess i need to change the cellClicked.connect to something else, which corresponds to selecting range?

            jsulmJ 1 Reply Last reply
            0
            • P Piyush

              @jsulm sender() provides the object name when we select a single cell withing the object. However, in my case I need to select a range of cells. So, sender() is not providing any signal if I select a range.

              I guess i need to change the cellClicked.connect to something else, which corresponds to selecting range?

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

              @Piyush As far as I know you get http://doc.qt.io/qt-5/qtablewidget.html#itemSelectionChanged even if more than one cell is selected and you can get selected cells using http://doc.qt.io/qt-5/qtablewidget.html#selectedItems.
              Calling sender() in slot connected to itemSelectionChanged signal should give you the table widget where the selection was done.

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

              P 1 Reply Last reply
              1
              • jsulmJ jsulm

                @Piyush As far as I know you get http://doc.qt.io/qt-5/qtablewidget.html#itemSelectionChanged even if more than one cell is selected and you can get selected cells using http://doc.qt.io/qt-5/qtablewidget.html#selectedItems.
                Calling sender() in slot connected to itemSelectionChanged signal should give you the table widget where the selection was done.

                P Offline
                P Offline
                Piyush
                wrote on last edited by
                #7

                @jsulm I am quite new to Qt. Can you please share an example in Python?

                1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Piyush What is the use case? Why do you need to generate object name like this? Sounds quite unusual...
                  And also: you're actually not generating object name but variable name (at least you try)!
                  This, somehow, does not make sense:

                  self.table123 = "self.ui." + table
                  self.table123 = QTableWidget()
                  

                  First you assign a string and then a QTableWidget instance. So, the result will be that self.table123 will contain a QTableWidget() instance, doesn't matter what you selected.
                  Is it possible that you actually want to use http://doc.qt.io/qt-5/qobject.html#objectName-prop?

                  P Offline
                  P Offline
                  Piyush
                  wrote on last edited by Piyush
                  #8

                  @jsulm You are correct on this thing. Implementing it in this way is wrong as it will return a QTableWidget instance and not the name.

                  self.table123 = "self.ui." + table
                  

                  This provides a string instead of <class 'PyQt5.QtWidgets.QTableWidget'>. Can you please advise how I can get it as <class 'PyQt5.QtWidgets.QTableWidget'>??

                  jsulmJ 1 Reply Last reply
                  0
                  • P Piyush

                    @jsulm You are correct on this thing. Implementing it in this way is wrong as it will return a QTableWidget instance and not the name.

                    self.table123 = "self.ui." + table
                    

                    This provides a string instead of <class 'PyQt5.QtWidgets.QTableWidget'>. Can you please advise how I can get it as <class 'PyQt5.QtWidgets.QTableWidget'>??

                    jsulmJ Online
                    jsulmJ Online
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Piyush Did you try to use sender()? As I said it should work even if you select more than one cell. Simply connect as slot to itemSelectionChanged signal and call sender() there.

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

                    P 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @Piyush Did you try to use sender()? As I said it should work even if you select more than one cell. Simply connect as slot to itemSelectionChanged signal and call sender() there.

                      P Offline
                      P Offline
                      Piyush
                      wrote on last edited by Piyush
                      #10

                      @jsulm I am not sure how to use the itemSelectionChanged signal. Is it like below:

                      self.ui.xray_tw1.itemSelectionChanged.connect(self.get_obj_name)
                      
                      def get_obj_name(self):
                              abc= self.sender()
                              table = abc.objectName()
                      
                      jsulmJ 1 Reply Last reply
                      0
                      • P Piyush

                        @jsulm I am not sure how to use the itemSelectionChanged signal. Is it like below:

                        self.ui.xray_tw1.itemSelectionChanged.connect(self.get_obj_name)
                        
                        def get_obj_name(self):
                                abc= self.sender()
                                table = abc.objectName()
                        
                        jsulmJ Online
                        jsulmJ Online
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @Piyush What is the problem now? I don't know what you want to achieve and what does not work now.

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

                        P 3 Replies Last reply
                        0
                        • jsulmJ jsulm

                          @Piyush What is the problem now? I don't know what you want to achieve and what does not work now.

                          P Offline
                          P Offline
                          Piyush
                          wrote on last edited by Piyush
                          #12
                          This post is deleted!
                          1 Reply Last reply
                          0
                          • jsulmJ jsulm

                            @Piyush What is the problem now? I don't know what you want to achieve and what does not work now.

                            P Offline
                            P Offline
                            Piyush
                            wrote on last edited by Piyush
                            #13
                            This post is deleted!
                            1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @Piyush What is the problem now? I don't know what you want to achieve and what does not work now.

                              P Offline
                              P Offline
                              Piyush
                              wrote on last edited by
                              #14

                              @jsulm Sorry for the confusion. I got it now. Thanks for being patient with me.

                              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