Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91358 > unrolled thread

[QT] Scroll multiple lists with one scrollbar

Started byAlexis Dubois <alex@duboaa.net>
First post2015-05-28 02:50 -0700
Last post2015-05-28 05:54 -0700
Articles 9 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  [QT] Scroll multiple lists with one scrollbar Alexis Dubois <alex@duboaa.net> - 2015-05-28 02:50 -0700
    Re: [QT] Scroll multiple lists with one scrollbar Laura Creighton <lac@openend.se> - 2015-05-28 12:11 +0200
      Re: [QT] Scroll multiple lists with one scrollbar Alexis Dubois <alex@duboaa.net> - 2015-05-28 03:44 -0700
        Re: [QT] Scroll multiple lists with one scrollbar Laura Creighton <lac@openend.se> - 2015-05-28 12:54 +0200
    Re: [QT] Scroll multiple lists with one scrollbar Laura Creighton <lac@openend.se> - 2015-05-28 14:18 +0200
      Re: [QT] Scroll multiple lists with one scrollbar Alexis Dubois <alex@duboaa.net> - 2015-05-28 05:53 -0700
        Re: [QT] Scroll multiple lists with one scrollbar Laura Creighton <lac@openend.se> - 2015-05-28 17:05 +0200
    Re: [QT] Scroll multiple lists with one scrollbar Peter Otten <__peter__@web.de> - 2015-05-28 14:35 +0200
      Re: [QT] Scroll multiple lists with one scrollbar Alexis Dubois <alex@duboaa.net> - 2015-05-28 05:54 -0700

#91358 — [QT] Scroll multiple lists with one scrollbar

FromAlexis Dubois <alex@duboaa.net>
Date2015-05-28 02:50 -0700
Subject[QT] Scroll multiple lists with one scrollbar
Message-ID<53f83314-12a6-4368-894f-13e756b5a888@googlegroups.com>
Hello everyone!

My QT GUI contains 8 QlistWidgets filled with a large amount of data.
Each item of a list is related to items of other lists in the same row.
So I want to scroll the 8 lists with only one vertical scrollbar (and vice-versa)

But I don't know how to manage this.
Do you have an idea?

(I'm quite new in python, I'm translating my tcl/tk app to this code)
thanks in advance

[toc] | [next] | [standalone]


#91359

FromLaura Creighton <lac@openend.se>
Date2015-05-28 12:11 +0200
Message-ID<mailman.124.1432807913.5151.python-list@python.org>
In reply to#91358
You want to define a scrollable area and then add your labels to it.
The code here: http://stackoverflow.com/questions/22255994/pyqt-adding-widgets-to-scrollarea-during-the-runtime

should show you what you need to do, though for you the job is easier if you
do not need to add the labels after the app is running.

Laura

[toc] | [prev] | [next] | [standalone]


#91361

FromAlexis Dubois <alex@duboaa.net>
Date2015-05-28 03:44 -0700
Message-ID<6a5519e7-be54-4650-98bc-0446bd2316f0@googlegroups.com>
In reply to#91359
Le jeudi 28 mai 2015 12:12:42 UTC+2, Laura Creighton a écrit :
> You want to define a scrollable area and then add your labels to it.
> The code here: http://stackoverflow.com/questions/22255994/pyqt-adding-widgets-to-scrollarea-during-the-runtime
> 
> should show you what you need to do, though for you the job is easier if you
> do not need to add the labels after the app is running.
> 
> Laura

Thanks Laura.
But as I understand the scrollable area, it's useful to scroll widgets.
But here, in my case, I want to scroll inside my widgets.
My QlistWidgets are fixed in size and data are append inside.
Because I want only one scrollbar for all lists, I set the "setVerticalScrollBarPolicy" lists property to "ScrollBarAlwaysOff" and tried to do what I need with a QScrollBar.

[toc] | [prev] | [next] | [standalone]


#91362

FromLaura Creighton <lac@openend.se>
Date2015-05-28 12:54 +0200
Message-ID<mailman.126.1432810463.5151.python-list@python.org>
In reply to#91361
In a message of Thu, 28 May 2015 03:44:22 -0700, Alexis Dubois writes:
>Le jeudi 28 mai 2015 12:12:42 UTC+2, Laura Creighton a écrit :
>> You want to define a scrollable area and then add your labels to it.
>> The code here: http://stackoverflow.com/questions/22255994/pyqt-adding-widgets-to-scrollarea-during-the-runtime
>> 
>> should show you what you need to do, though for you the job is easier if you
>> do not need to add the labels after the app is running.
>> 
>> Laura
>
>Thanks Laura.
>But as I understand the scrollable area, it's useful to scroll widgets.
>But here, in my case, I want to scroll inside my widgets.
>My QlistWidgets are fixed in size and data are append inside.
>Because I want only one scrollbar for all lists, I set the "setVerticalScrollBarPolicy" lists property to "ScrollBarAlwaysOff" and tried to do what I need with a QScrollBar.

Ah, sorry, I misunderstood the question.

Hmmm.  I've never tried to do that.  Let me see if I can get something
to work.

Back later,
hack hack hack!
Laura

[toc] | [prev] | [next] | [standalone]


#91366

FromLaura Creighton <lac@openend.se>
Date2015-05-28 14:18 +0200
Message-ID<mailman.130.1432815493.5151.python-list@python.org>
In reply to#91358
Looks like what you need to do is to 
connect verticalScrollBar().valueChanged (in one widget) to
verticalScrollBar().setValue in all of the others.

So is this code on the right track?  It uses lists, not labels, and
doesn't hide the scrollbars, but is this the behaviour you need (
and weren't getting)?  It should work for labels too..


from PyQt4 import QtGui, QtCore

class Window(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        self.listA = QtGui.QListWidget(self)
        self.listB = QtGui.QListWidget(self)
        self.listC = QtGui.QListWidget(self)

        widgets=[self.listA, self.listB, self.listC]
        layout = QtGui.QHBoxLayout(self)

        for w1 in widgets:
            layout.addWidget(w1)
            for index in range(100):
                w1.addItem('This is line number %d' % (index +1))
            for w2 in widgets:
                if w1 != w2:
                    w1.verticalScrollBar().valueChanged.connect(w2.verticalScrollBar().setValue)
            
if __name__ == '__main__':

    import sys
    app = QtGui.QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())

[toc] | [prev] | [next] | [standalone]


#91368

FromAlexis Dubois <alex@duboaa.net>
Date2015-05-28 05:53 -0700
Message-ID<b5b2a476-644f-4bae-be5a-d3c2329de0d3@googlegroups.com>
In reply to#91366
Thank you Laura, it works.
(Even if connecting the scrollbar of one list to other lists is not what I exactly want to do, but no matter, I change the line "w1.verticalScrollBar().valueChanged.connect(w2.verticalScrollBar().setValue)" a little bit to fit my need. )

[toc] | [prev] | [next] | [standalone]


#91375

FromLaura Creighton <lac@openend.se>
Date2015-05-28 17:05 +0200
Message-ID<mailman.134.1432825577.5151.python-list@python.org>
In reply to#91368
In a message of Thu, 28 May 2015 05:53:34 -0700, Alexis Dubois writes:
>Thank you Laura, it works.
>(Even if connecting the scrollbar of one list to other lists is not what I exactly want to do, but no matter, I change the line "w1.verticalScrollBar().valueChanged.connect(w2.verticalScrollBar().setValue)" a little bit to fit my need. )

Great, I had to go to a meeting, so things were not in such a nice
state as I would have liked.  In particular, if some of your lists
are never going to have any scroll bars attatched to them, there is
no need to wire them up to the thing.  But I thought  I had found
the little bit of magic you needed; glad I was correct this time.

Laura

[toc] | [prev] | [next] | [standalone]


#91367

FromPeter Otten <__peter__@web.de>
Date2015-05-28 14:35 +0200
Message-ID<mailman.131.1432816538.5151.python-list@python.org>
In reply to#91358
Alexis Dubois wrote:

> My QT GUI contains 8 QlistWidgets filled with a large amount of data.
> Each item of a list is related to items of other lists in the same row.
> So I want to scroll the 8 lists with only one vertical scrollbar (and
> vice-versa)
> 
> But I don't know how to manage this.
> Do you have an idea?
> 
> (I'm quite new in python, I'm translating my tcl/tk app to this code)
> thanks in advance

Are you perhaps looking for a table widget?

https://srinikom.github.io/pyside-docs/PySide/QtGui/QTableWidget.html

[toc] | [prev] | [next] | [standalone]


#91369

FromAlexis Dubois <alex@duboaa.net>
Date2015-05-28 05:54 -0700
Message-ID<049fb2f7-ce86-4817-849f-8f934fc69b05@googlegroups.com>
In reply to#91367
Thanks Peter, but no, even if it could be possible to use a QTableWidget instead of my 8 lists.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web