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

  • Home
  • SEARCH
  • 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 8256111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:45:03+00:00 2026-06-08T01:45:03+00:00

I’m having trouble finding the correct centre of the QScrollBar’s slider (I need to

  • 0

I’m having trouble finding the correct centre of the QScrollBar’s slider (I need to stick a text widget to it to display the position of the slider). I tried normalising the slider’s position by dividing it by the document width, then scaling it by it’s width(). But that’s not accurate because the scroll bar’s decorations and buttons are not taken into account. So the label wanders off as you drag and won’t stick to the centre.
Below is my current code which somehow need to take into account the QScrollBar’s buttons, frames etc to find the correct start and end position of the scroll area.
Could somebody help please?

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

class PageScroller(QScrollBar):
    '''Set the total number of pages.'''
    def __init__(self, parent=None):
        super(PageScroller, self).__init__(parent)

        self.pageIndicator = QLabel('|', parent)
        self.valueChanged.connect(self.updateSlider)
        self.setOrientation(Qt.Orientation.Horizontal)
        self.setPageStep(1)

    def updateSlider(self, event):
        scrollAreaWidth = self.maximum() - self.minimum() + self.pageStep()
        sliderPos = (self.sliderPosition() + self.pageStep()/2.0) / float(scrollAreaWidth) * self.width()
        indicatorPos = QPoint(sliderPos - self.pageIndicator.width()/2, -self.pageIndicator.height())
        self.pageIndicator.move(self.mapToParent(indicatorPos))

        self.update()


if __name__ == '__main__':

    app = QApplication(sys.argv)
    #app.setStyle('plastique') # tyhis makes the sliding more obvious
    mainWindow = QWidget()
    layout = QVBoxLayout(mainWindow)
    s = PageScroller(mainWindow)
    layout.addWidget(s)
    mainWindow.resize(400, 100)
    mainWindow.show()


    sys.exit(app.exec_())
  • 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-08T01:45:05+00:00Added an answer on June 8, 2026 at 1:45 am

    It would be really hard, like you have discovered, to properly map a pixel range of the slider portion, while accounting for the various style differences between platforms. Too many factors (extra buttons on the left and right, the slider size itself, …)

    This is really obscure, and it takes a bit of hunting to find it out, but you actually need to query for the SubControl of the QScrollBar. What you can get back is a QRect of the scroll handle:

    def resizeEvent(self, event):
        super(PageScroller, self).resizeEvent(event)
        self.updateSlider()
    
    def updateSlider(self, val=None):
        opt = QStyleOptionSlider()
        self.initStyleOption(opt)
        style = self.style()
        handle = style.subControlRect(style.CC_ScrollBar, opt, 
                                        style.SC_ScrollBarSlider)
        sliderPos = handle.center()
        sliderPos.setY(-self.pageIndicator.height())
        self.pageIndicator.move(self.mapToParent(sliderPos))
    
    1. You first have to create an empty QStyleOptionSlider, and have it populated with the current state of your PageScroller.
    2. Then you have to take the style from the PageScroller, and use subControlRect to query the subcontrol of a ComplexControl ScrollBar type, for the SubControl ScrollBarSlider type. It uses the opts to return you a QRect of the slider
    3. Then you can map as normal and move the pageIndicator

    I added a resizeEvent to also properly place the indicator at first show, and during any resizes of the widget.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but

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.