N
N
Nikita Kuzovkov2022-01-07 11:51:10
PyQt
Nikita Kuzovkov, 2022-01-07 11:51:10

The scrollbar returns to its default PyQt5 state. What's wrong?

I am writing an interface for a text editor, where I synchronize two scrollbars with the following script:

self.list_of_tables = [self.lines,self.text]

def move_other_scrollbars(idx,bar):
    scrollbars = {tbl.verticalScrollBar() for tbl in self.list_of_tables}
    scrollbars.remove(bar)
    for bar in scrollbars:
        print(idx)
        bar.setValue(idx)

    for tbl in self.list_of_tables:
        scrollbar = tbl.verticalScrollBar()
        scrollbar.valueChanged.connect(lambda idx,bar=scrollbar: move_other_scrollbars(idx, bar))


self.linesis a QTextBrowser that cannot be changed, it displays lines, and self.textis a QTextEdit, in which the text itself is edited. I hid the scrollbar from the rows, but that's not the problem. All this moves synchronously, but as soon as you start selecting from the bottom up, something is updated, apparently, and the scrollbar returns to the 0th state. I even print(idx)decided to display the values, and this is what I got:
80
69
69
89
0
0 (two zeros is the moment where I click on the text, lowering the scrollbar below)

I analyzed the code and realized that the problem is one hundred percent in updating the widget, in line:bar.setValue(idx)

Help get rid of this update so that it works correctly. The script above is not taken out of context, I described the two widgets with which it works - it is quite independent

Screenshot of the editor:
61d7fc158fb20743879980.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question