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 8151103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:16:08+00:00 2026-06-06T15:16:08+00:00

I am trying to build a GUI that has three horizontal sliders that control

  • 0

I am trying to build a GUI that has three horizontal sliders that control some probability. Each slider can range between 0 – 1.0 but all three together must equal 1.0 at all times. Here is a link I found that does what I want but with jQuery.

Is there any good way of doing this in Qt? PyQt more specifically but I think pseudo code will suffice.

  • 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-06T15:16:11+00:00Added an answer on June 6, 2026 at 3:16 pm
    class MainWindow(QWidget):
        def __init__(self):
            QWidget.__init__(self)
            layout = QGridLayout()
            self.sliders = []
            slider_amount = 3
            slider_precision = 10000 # sliders work only with ints, so large ints are used and mapped to floats
            for i in range(slider_amount):
                slider = QSlider(Qt.Horizontal)
                slider.setRange(0, slider_amount*slider_precision)
                slider.setSingleStep(slider.maximum()/100.0)
                slider.setPageStep(slider.maximum()/20.0)
                slider.valueChanged.connect(self.on_slider_value_changed)
                slider.float_value = (i+1)/((1+slider_amount)/2.0*slider_amount) # provide your own default values
                slider.label = QLabel()
                self.sliders.append(slider)
                layout.addWidget(slider, i, 0)
                layout.addWidget(slider.label, i, 1)
            self.update_slider_values()
            self.setLayout(layout)
            self.show()
    
        def on_slider_value_changed(self, value):
            changed_slider = self.sender()
            changed_slider.float_value = float(value)/changed_slider.maximum()
            delta = sum(slider.float_value for slider in self.sliders)-1
            while abs(delta)>0.00001:
                d = len(self.sliders)-1
                for slider in self.sliders:
                    if slider is changed_slider:
                        continue
                    old_value = slider.float_value
                    slider.float_value = min(max(0, old_value-delta/d), 1)
                    delta -= old_value-slider.float_value
                    d -= 1
            self.update_slider_values()
    
        def update_slider_values(self):
            for slider in self.sliders:
                slider_signals_blocked = slider.blockSignals(True)
                slider.setValue(round(slider.float_value*slider.maximum()))
                slider.blockSignals(slider_signals_blocked)
                slider.label.setText('{:.2f}'.format(slider.float_value))
    
    app = QApplication(sys.argv)
    mw = MainWindow()
    app.exec_()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a weird problem while trying to build a Traits GUI that
I'm trying to build an application that displays in a GUI the contents of
I am trying to build a simple GUI app in java that will show
I'm trying to build a GUI window in my application. What I'm trying to
I'm trying build an App Engine connected Android application and am having some problems
I'm trying to build a simple utility for kids where they can play games
I'm trying to build a really basic program that will alternate between two pictures
I am using cmake-gui trying to build opencv but get this error: CMake Error
I find some people are trying to build their project by NAnt instead of
I'm creating a GUI application that can monitor and manipulate a stream of messages.

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.