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. Problem with setting the textBrowser text using a variable
Forum Updated to NodeBB v4.3 + New Features

Problem with setting the textBrowser text using a variable

Scheduled Pinned Locked Moved Solved Qt for Python
5 Posts 2 Posters 2.2k 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.
  • D Offline
    D Offline
    Davidhahaha
    wrote on last edited by
    #1

    I am having a problem with setting the text of textBrowser on PYQT5.
    It is ok when I assign a string.
    """self.textBrowser.setText("string")"""

    But it does nothing when I assign a variable.
    """self.textBrowser.setText(lst)"""

    sorting.bubble_sort(text) is function which return an array

    def run(self):
            try:
                text = "534 23 654 43 21 2"
                text = Ui_MainWindow.str_list_to_int_list(text.split())
                lst=simulator_cal.sorting.bubble_sort(text)
                
                self.textBrowser.setText(lst)
                self.textBrowser.repaint()
    
            except:
                None
    
    JonBJ 1 Reply Last reply
    0
    • D Davidhahaha

      Thanks for your response.
      lst is a string like "2, 21, 23, 43, 534, 654", but that is not working.
      It is working when the lst like "123".
      textBrowser is a object of QTextBrowser.
      setText() is the function from PYQT.

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

      @Davidhahaha
      Sorry I was wrong about QTextBrowser not having setText(), I have corrected that.

      lst is a string like "2, 21, 23, 43, 534, 654"

      So you have a function str_list_to_int_list(text.split()) which accepts a list but returns a string? And/or, simulator_cal.sorting.bubble_sort(text) takes a list/string depending, but returns its answer as a string, does it? You originally said:

      sorting.bubble_sort(text) is function which return an array

      https://doc.qt.io/qt-5/qtextbrowser.html

      The QTextBrowser class provides a rich text browser with hypertext navigation

      I don't know what it does with a plain text input, nor why you would want to use it.

      I'll have to leave someone else to help you further.

      D 1 Reply Last reply
      0
      • D Davidhahaha

        I am having a problem with setting the text of textBrowser on PYQT5.
        It is ok when I assign a string.
        """self.textBrowser.setText("string")"""

        But it does nothing when I assign a variable.
        """self.textBrowser.setText(lst)"""

        sorting.bubble_sort(text) is function which return an array

        def run(self):
                try:
                    text = "534 23 654 43 21 2"
                    text = Ui_MainWindow.str_list_to_int_list(text.split())
                    lst=simulator_cal.sorting.bubble_sort(text)
                    
                    self.textBrowser.setText(lst)
                    self.textBrowser.repaint()
        
                except:
                    None
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #2

        @Davidhahaha
        You don't say what type textBrowser is, which is going to be needed to answer this question. If I have to guess it's QTextBrowser, I don't see that has any setText() method. And if it did it would be intended to take rich (HTML) text....

        You do not show what is in lst after simulator_cal.sorting.bubble_sort(text).

        QTextBrowser does not accept a list as an argument.

        If lst is a list of ints, it's not going to be suitable, in any case, and certainly not for passing to function named setText().

        Your repaint() is unlikely to do anything.

        Whatever your issues are, it will not be because you are using a variable. Rather it will be a question of the value & type of the variable.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Davidhahaha
          wrote on last edited by
          #3

          Thanks for your response.
          lst is a string like "2, 21, 23, 43, 534, 654", but that is not working.
          It is working when the lst like "123".
          textBrowser is a object of QTextBrowser.
          setText() is the function from PYQT.

          JonBJ 1 Reply Last reply
          0
          • D Davidhahaha

            Thanks for your response.
            lst is a string like "2, 21, 23, 43, 534, 654", but that is not working.
            It is working when the lst like "123".
            textBrowser is a object of QTextBrowser.
            setText() is the function from PYQT.

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

            @Davidhahaha
            Sorry I was wrong about QTextBrowser not having setText(), I have corrected that.

            lst is a string like "2, 21, 23, 43, 534, 654"

            So you have a function str_list_to_int_list(text.split()) which accepts a list but returns a string? And/or, simulator_cal.sorting.bubble_sort(text) takes a list/string depending, but returns its answer as a string, does it? You originally said:

            sorting.bubble_sort(text) is function which return an array

            https://doc.qt.io/qt-5/qtextbrowser.html

            The QTextBrowser class provides a rich text browser with hypertext navigation

            I don't know what it does with a plain text input, nor why you would want to use it.

            I'll have to leave someone else to help you further.

            D 1 Reply Last reply
            0
            • JonBJ JonB

              @Davidhahaha
              Sorry I was wrong about QTextBrowser not having setText(), I have corrected that.

              lst is a string like "2, 21, 23, 43, 534, 654"

              So you have a function str_list_to_int_list(text.split()) which accepts a list but returns a string? And/or, simulator_cal.sorting.bubble_sort(text) takes a list/string depending, but returns its answer as a string, does it? You originally said:

              sorting.bubble_sort(text) is function which return an array

              https://doc.qt.io/qt-5/qtextbrowser.html

              The QTextBrowser class provides a rich text browser with hypertext navigation

              I don't know what it does with a plain text input, nor why you would want to use it.

              I'll have to leave someone else to help you further.

              D Offline
              D Offline
              Davidhahaha
              wrote on last edited by
              #5

              @JonB Thank you sir.
              I have finished the problem

              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