[PyQt] Re: problem with connected scrollbars

Vicent Mas uvemas at gmail.com
Wed Nov 12 11:41:49 GMT 2008


Hi,

thanks for your answer. I've been working about the TypeError and I've found 
that the call

my_scrollbar.triggerAction(QtGui.QAbstractSlider.SliderSingleStepAdd)

works

but the (apparently equivalent) call

my_scrollbar.triggerAction(1)

fails raising the TypeError. However QAbstractSlider.SliderSingleStepAdd is 
supposed to have an integer value of 1, isn't it? At least this is what I 
understand when reading the Qt docs.

Even more, the actionTriggered SIGNAL passes integer values to the slot it is 
connected. So I supposed that I could use this values directly for triggering 
the same action in other scrollbar, but I cannot. Instead the constants names 
have to be used. Could you (or somebody else :-) tell me why?

Thanks.

PS: and thanks for your code, of course.

 
El Wednesday 12 November 2008 Georg Altmann escribió:
> Vicent Mas schrieb:
> > Hello,
> >
> > I'm trying to make a QTableView with two 'connected' vertical scrollbars.
> > By connected I mean that the second scrollbar should be able to act on
> > the first one. As a simple case I want the first scrollbar to repeat the
> > action triggered by the second one. For instance, if I press the down
> > arrow of the second scrollbar I want the down arrow of the first
> > scrollbar to be pressed too. The attached script tries to do it. However
> > an unexpected (unexpected for me I mean :-) TypeError makes the script to
> > fail. Could someone help me with this problem, please?
>
> You didn't write were the error actually occurs. Anyway I had the same
> problem of linking multiple scollbars. My solution is below. Of course
> this only makes sense if the sliders have the same range. Otherwise the
> class could be modified to use relative values. Depends on what you want
> to accomplish.
>
> Use the class like this:
>
> mySliderLinker = SliderLinker([scrollbar1, scrollbar2])
>
> Regards
> Georg
>
>
> from PyQt4 import QtCore,QtGui
> from PyQt4.QtCore import SIGNAL,SLOT
>
>
> class SliderLinker(QtCore.QObject):
>      '''Links multiple QAbstractSlider s together.
>
>      If one slider's value changes, the other linked sliders will be set
>
>      to this value.'''
>
>      def __init__(self, sliders, parent = None):
>          super(SliderLinker,self).__init__(parent)
>          self._sliders = sliders
>          self._linkerSlots = []
>          self.initSliders()
>
>      def initSliders(self):
>          for s in self._sliders:
>              ls = LinkerSlot(self,s)
>              self._linkerSlots.append(ls)
>
>      def updateFrom(self,slider):
>          val = slider.value()
>          for s in self._sliders:
>              if(s is not slider):
>                  s.setValue(val)
>
> class LinkerSlot(QtCore.QObject):
>      def __init__(self,linker,slider, parent = None):
>          super(LinkerSlot,self).__init__(parent)
>          self._linker = linker
>          self._slider = slider
>          self.connect(slider, SIGNAL('valueChanged(int)'),
>                  self.updateSliders)
>
>      def updateSliders(self, value):
>          self._linker.updateFrom(self._slider)
>
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt



-- 
::

	Share what you know, learn what you don't




More information about the PyQt mailing list