Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problem with setting the textBrowser text using a variable



  • 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
    


  • @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.



  • @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.



  • 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.



  • @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.



  • @JonB Thank you sir.
    I have finished the problem


Log in to reply