Reading text value from Qtablewidget and assign automatically to Qcombobox












1















I have a QTableWidget and a Qcombobox. I want to get text values from every single cell in first column 1 and when ever a user inserts a new value, that would assign and set automatically to Qcombobox. What I mean by every single cell is to get available values, when a cell is empty then do nothing.



Visualization:



enter image description here



from PyQt5 import QtCore, QtWidgets

class Widget(QtWidgets.QWidget):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.setLayout(QtWidgets.QVBoxLayout())
combo = QtWidgets.QComboBox(self)
self.layout().addWidget(combo)

class Window(QtWidgets.QWidget):
def __init__(self):
super(Window, self).__init__()
self.table = QtWidgets.QTableWidget(10, 2, self)
self.comboBox = QtWidgets.QComboBox()
layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(self.table)
names = ['Name 1', 'Name 2', 'Name 3', 'Name 4', 'Name 5']
for index, name in enumerate(names):
self.table.setItem(index, 0, QtWidgets.QTableWidgetItem(name))

class Layout(QtWidgets.QWidget):
def __init__(self, parent=None):
super(Layout, self).__init__()
self.comb = Widget()
self.table = Window()

layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(self.table)
layout.addWidget(self.comb)

if __name__ == '__main__':

import sys
app = QtWidgets.QApplication(sys.argv)
window = Layout()
window.setGeometry(600, 200, 300, 300)
window.show()
sys.exit(app.exec_())


I am not sure about connection and slot solution will give a good choose?










share|improve this question





























    1















    I have a QTableWidget and a Qcombobox. I want to get text values from every single cell in first column 1 and when ever a user inserts a new value, that would assign and set automatically to Qcombobox. What I mean by every single cell is to get available values, when a cell is empty then do nothing.



    Visualization:



    enter image description here



    from PyQt5 import QtCore, QtWidgets

    class Widget(QtWidgets.QWidget):
    def __init__(self, parent=None):
    QtWidgets.QWidget.__init__(self, parent)
    self.setLayout(QtWidgets.QVBoxLayout())
    combo = QtWidgets.QComboBox(self)
    self.layout().addWidget(combo)

    class Window(QtWidgets.QWidget):
    def __init__(self):
    super(Window, self).__init__()
    self.table = QtWidgets.QTableWidget(10, 2, self)
    self.comboBox = QtWidgets.QComboBox()
    layout = QtWidgets.QVBoxLayout(self)
    layout.addWidget(self.table)
    names = ['Name 1', 'Name 2', 'Name 3', 'Name 4', 'Name 5']
    for index, name in enumerate(names):
    self.table.setItem(index, 0, QtWidgets.QTableWidgetItem(name))

    class Layout(QtWidgets.QWidget):
    def __init__(self, parent=None):
    super(Layout, self).__init__()
    self.comb = Widget()
    self.table = Window()

    layout = QtWidgets.QVBoxLayout(self)
    layout.addWidget(self.table)
    layout.addWidget(self.comb)

    if __name__ == '__main__':

    import sys
    app = QtWidgets.QApplication(sys.argv)
    window = Layout()
    window.setGeometry(600, 200, 300, 300)
    window.show()
    sys.exit(app.exec_())


    I am not sure about connection and slot solution will give a good choose?










    share|improve this question



























      1












      1








      1








      I have a QTableWidget and a Qcombobox. I want to get text values from every single cell in first column 1 and when ever a user inserts a new value, that would assign and set automatically to Qcombobox. What I mean by every single cell is to get available values, when a cell is empty then do nothing.



      Visualization:



      enter image description here



      from PyQt5 import QtCore, QtWidgets

      class Widget(QtWidgets.QWidget):
      def __init__(self, parent=None):
      QtWidgets.QWidget.__init__(self, parent)
      self.setLayout(QtWidgets.QVBoxLayout())
      combo = QtWidgets.QComboBox(self)
      self.layout().addWidget(combo)

      class Window(QtWidgets.QWidget):
      def __init__(self):
      super(Window, self).__init__()
      self.table = QtWidgets.QTableWidget(10, 2, self)
      self.comboBox = QtWidgets.QComboBox()
      layout = QtWidgets.QVBoxLayout(self)
      layout.addWidget(self.table)
      names = ['Name 1', 'Name 2', 'Name 3', 'Name 4', 'Name 5']
      for index, name in enumerate(names):
      self.table.setItem(index, 0, QtWidgets.QTableWidgetItem(name))

      class Layout(QtWidgets.QWidget):
      def __init__(self, parent=None):
      super(Layout, self).__init__()
      self.comb = Widget()
      self.table = Window()

      layout = QtWidgets.QVBoxLayout(self)
      layout.addWidget(self.table)
      layout.addWidget(self.comb)

      if __name__ == '__main__':

      import sys
      app = QtWidgets.QApplication(sys.argv)
      window = Layout()
      window.setGeometry(600, 200, 300, 300)
      window.show()
      sys.exit(app.exec_())


      I am not sure about connection and slot solution will give a good choose?










      share|improve this question
















      I have a QTableWidget and a Qcombobox. I want to get text values from every single cell in first column 1 and when ever a user inserts a new value, that would assign and set automatically to Qcombobox. What I mean by every single cell is to get available values, when a cell is empty then do nothing.



      Visualization:



      enter image description here



      from PyQt5 import QtCore, QtWidgets

      class Widget(QtWidgets.QWidget):
      def __init__(self, parent=None):
      QtWidgets.QWidget.__init__(self, parent)
      self.setLayout(QtWidgets.QVBoxLayout())
      combo = QtWidgets.QComboBox(self)
      self.layout().addWidget(combo)

      class Window(QtWidgets.QWidget):
      def __init__(self):
      super(Window, self).__init__()
      self.table = QtWidgets.QTableWidget(10, 2, self)
      self.comboBox = QtWidgets.QComboBox()
      layout = QtWidgets.QVBoxLayout(self)
      layout.addWidget(self.table)
      names = ['Name 1', 'Name 2', 'Name 3', 'Name 4', 'Name 5']
      for index, name in enumerate(names):
      self.table.setItem(index, 0, QtWidgets.QTableWidgetItem(name))

      class Layout(QtWidgets.QWidget):
      def __init__(self, parent=None):
      super(Layout, self).__init__()
      self.comb = Widget()
      self.table = Window()

      layout = QtWidgets.QVBoxLayout(self)
      layout.addWidget(self.table)
      layout.addWidget(self.comb)

      if __name__ == '__main__':

      import sys
      app = QtWidgets.QApplication(sys.argv)
      window = Layout()
      window.setGeometry(600, 200, 300, 300)
      window.show()
      sys.exit(app.exec_())


      I am not sure about connection and slot solution will give a good choose?







      python pyqt pyqt5 qtablewidget qcombobox






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 0:19









      eyllanesc

      83.3k103562




      83.3k103562










      asked Jan 2 at 23:58









      Pavel.DPavel.D

      851111




      851111
























          1 Answer
          1






          active

          oldest

          votes


















          1














          In this it is better to pass as a model so that it is automatically updated without the unnecessary use of signals. But since you want no empty elements to be displayed, use QSortFilterProxyModel with an appropriate regex:



          from PyQt5 import QtCore, QtWidgets

          class Window(QtWidgets.QWidget):
          def __init__(self):
          super(Window, self).__init__()
          self.table = QtWidgets.QTableWidget(10, 2)
          names = ['Name 1', 'Name 2', 'Name 3', 'Name 4', 'Name 5']
          for index, name in enumerate(names):
          self.table.setItem(index, 0, QtWidgets.QTableWidgetItem(name))

          proxy = QtCore.QSortFilterProxyModel(self)
          proxy.setSourceModel(self.table.model())
          proxy.setFilterRegExp(r"^(?!s*$).+")

          self.comboBox = QtWidgets.QComboBox()
          self.comboBox.setModel(proxy)
          self.comboBox.setModelColumn(0)

          layout = QtWidgets.QVBoxLayout(self)
          layout.addWidget(self.table)
          layout.addWidget(self.comboBox)

          if __name__ == '__main__':
          import sys
          app = QtWidgets.QApplication(sys.argv)
          window = Window()
          window.setGeometry(600, 200, 300, 300)
          window.show()
          sys.exit(app.exec_())





          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54014730%2freading-text-value-from-qtablewidget-and-assign-automatically-to-qcombobox%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            In this it is better to pass as a model so that it is automatically updated without the unnecessary use of signals. But since you want no empty elements to be displayed, use QSortFilterProxyModel with an appropriate regex:



            from PyQt5 import QtCore, QtWidgets

            class Window(QtWidgets.QWidget):
            def __init__(self):
            super(Window, self).__init__()
            self.table = QtWidgets.QTableWidget(10, 2)
            names = ['Name 1', 'Name 2', 'Name 3', 'Name 4', 'Name 5']
            for index, name in enumerate(names):
            self.table.setItem(index, 0, QtWidgets.QTableWidgetItem(name))

            proxy = QtCore.QSortFilterProxyModel(self)
            proxy.setSourceModel(self.table.model())
            proxy.setFilterRegExp(r"^(?!s*$).+")

            self.comboBox = QtWidgets.QComboBox()
            self.comboBox.setModel(proxy)
            self.comboBox.setModelColumn(0)

            layout = QtWidgets.QVBoxLayout(self)
            layout.addWidget(self.table)
            layout.addWidget(self.comboBox)

            if __name__ == '__main__':
            import sys
            app = QtWidgets.QApplication(sys.argv)
            window = Window()
            window.setGeometry(600, 200, 300, 300)
            window.show()
            sys.exit(app.exec_())





            share|improve this answer






























              1














              In this it is better to pass as a model so that it is automatically updated without the unnecessary use of signals. But since you want no empty elements to be displayed, use QSortFilterProxyModel with an appropriate regex:



              from PyQt5 import QtCore, QtWidgets

              class Window(QtWidgets.QWidget):
              def __init__(self):
              super(Window, self).__init__()
              self.table = QtWidgets.QTableWidget(10, 2)
              names = ['Name 1', 'Name 2', 'Name 3', 'Name 4', 'Name 5']
              for index, name in enumerate(names):
              self.table.setItem(index, 0, QtWidgets.QTableWidgetItem(name))

              proxy = QtCore.QSortFilterProxyModel(self)
              proxy.setSourceModel(self.table.model())
              proxy.setFilterRegExp(r"^(?!s*$).+")

              self.comboBox = QtWidgets.QComboBox()
              self.comboBox.setModel(proxy)
              self.comboBox.setModelColumn(0)

              layout = QtWidgets.QVBoxLayout(self)
              layout.addWidget(self.table)
              layout.addWidget(self.comboBox)

              if __name__ == '__main__':
              import sys
              app = QtWidgets.QApplication(sys.argv)
              window = Window()
              window.setGeometry(600, 200, 300, 300)
              window.show()
              sys.exit(app.exec_())





              share|improve this answer




























                1












                1








                1







                In this it is better to pass as a model so that it is automatically updated without the unnecessary use of signals. But since you want no empty elements to be displayed, use QSortFilterProxyModel with an appropriate regex:



                from PyQt5 import QtCore, QtWidgets

                class Window(QtWidgets.QWidget):
                def __init__(self):
                super(Window, self).__init__()
                self.table = QtWidgets.QTableWidget(10, 2)
                names = ['Name 1', 'Name 2', 'Name 3', 'Name 4', 'Name 5']
                for index, name in enumerate(names):
                self.table.setItem(index, 0, QtWidgets.QTableWidgetItem(name))

                proxy = QtCore.QSortFilterProxyModel(self)
                proxy.setSourceModel(self.table.model())
                proxy.setFilterRegExp(r"^(?!s*$).+")

                self.comboBox = QtWidgets.QComboBox()
                self.comboBox.setModel(proxy)
                self.comboBox.setModelColumn(0)

                layout = QtWidgets.QVBoxLayout(self)
                layout.addWidget(self.table)
                layout.addWidget(self.comboBox)

                if __name__ == '__main__':
                import sys
                app = QtWidgets.QApplication(sys.argv)
                window = Window()
                window.setGeometry(600, 200, 300, 300)
                window.show()
                sys.exit(app.exec_())





                share|improve this answer















                In this it is better to pass as a model so that it is automatically updated without the unnecessary use of signals. But since you want no empty elements to be displayed, use QSortFilterProxyModel with an appropriate regex:



                from PyQt5 import QtCore, QtWidgets

                class Window(QtWidgets.QWidget):
                def __init__(self):
                super(Window, self).__init__()
                self.table = QtWidgets.QTableWidget(10, 2)
                names = ['Name 1', 'Name 2', 'Name 3', 'Name 4', 'Name 5']
                for index, name in enumerate(names):
                self.table.setItem(index, 0, QtWidgets.QTableWidgetItem(name))

                proxy = QtCore.QSortFilterProxyModel(self)
                proxy.setSourceModel(self.table.model())
                proxy.setFilterRegExp(r"^(?!s*$).+")

                self.comboBox = QtWidgets.QComboBox()
                self.comboBox.setModel(proxy)
                self.comboBox.setModelColumn(0)

                layout = QtWidgets.QVBoxLayout(self)
                layout.addWidget(self.table)
                layout.addWidget(self.comboBox)

                if __name__ == '__main__':
                import sys
                app = QtWidgets.QApplication(sys.argv)
                window = Window()
                window.setGeometry(600, 200, 300, 300)
                window.show()
                sys.exit(app.exec_())






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jan 3 at 0:28

























                answered Jan 3 at 0:17









                eyllanesceyllanesc

                83.3k103562




                83.3k103562
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54014730%2freading-text-value-from-qtablewidget-and-assign-automatically-to-qcombobox%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas