Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8025655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:14:02+00:00 2026-06-04T23:14:02+00:00

Consider a simple example like this which links two sliders using signals and slots:

  • 0

Consider a simple example like this which links two sliders using signals and slots:

from PySide.QtCore import *
from PySide.QtGui import *
import sys

class MyMainWindow(QWidget):
 def __init__(self):
  QWidget.__init__(self, None)

  vbox = QVBoxLayout()

  sone = QSlider(Qt.Horizontal)
  vbox.addWidget(sone)

  stwo = QSlider(Qt.Horizontal)
  vbox.addWidget(stwo)

  sone.valueChanged.connect(stwo.setValue)

if __name__ == '__main__':
 app = QApplication(sys.argv)
 w = MyMainWindow()
 w.show()
 sys.exit(app.exec_())

How would you change this so that the second slider moves in the opposite direction as the first? Slider one would be initialized with these values:

  sone.setRange(0,99)
  sone.setValue(0)

And slider two would be initialized with these values:

  stwo.setRange(0,99)
  stwo.setValue(99)

And then the value of stwo would be 99 - sone.sliderPosition.

How would you implement the signal and slot to make this work? I would appreciate a working example that builds on the simple example above.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:14:04+00:00Added an answer on June 4, 2026 at 11:14 pm

    Your example is a bit broken, because you forgot to set the parent of the layout, and also to save the slider widgets as member attributes to be accessed later… But to answer your question, its really as simple as just pointing your connection to your own function:

    class MyMainWindow(QWidget):
        def __init__(self):
            QWidget.__init__(self, None)
    
            vbox = QVBoxLayout(self)
    
            self.sone = QSlider(Qt.Horizontal)
            self.sone.setRange(0,99)
            self.sone.setValue(0)
            vbox.addWidget(self.sone)
    
            self.stwo = QSlider(Qt.Horizontal)
            self.stwo.setRange(0,99)
            self.stwo.setValue(99)
            vbox.addWidget(self.stwo)
    
            self.sone.valueChanged.connect(self.sliderChanged)
    
        def sliderChanged(self, val):
            self.stwo.setValue(self.stwo.maximum() - val)
    

    Note how sliderChanged() has the same signature as the original setValue() slot. Instead of connecting one widget directly to the other, you connect it to a custom method and then transform the value to what you want, and act how you want (setting a custom value on stwo)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this simple example (which displays in red): echo -e \033[31mHello World\033[0m It displays
I would like to write some simple Mario-like game from scratch using language C.
Consider the simple example below of implementing a method in an Enum. One problem
Consider this simple XML document. The serialized XML shown here is the result of
Consider this simple markup: <body> <div style=border: 2px solid navy; position:absolute; width:100%; height:100%> </div>
Consider this simple SVG file : <svg xmlns=http://www.w3.org/2000/svg xmlns:x=http://www.w3.org/1999/xlink viewBox=0 0 353 150> <defs>
Consider my first attempt, a simple type in F# like the following: type Test()
Please consider this -probably poorly written- example : class Command; class Command : public
Consider the following simple example: f[x_] = Sin[5 x] + Sin[3 x]; p1 =
Consider the following problem: We have two sequences of cargo loads which can contain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.