Results 1 to 2 of 2

Thread: How can I show/hide a QScrollBar on top of a widget instead of next to it?

  1. #1

    Question How can I show/hide a QScrollBar on top of a widget instead of next to it?

    I have an application where I have a main widget that is controlled by a horizontal QScrollBar. The main widget is quite involved so I can't use a QScrollArea so I am left to using regular a QScrollBar instead. Ultimately I want the scrollbar to show only when I hover on top of the lower part of the main widget, and I want it to show on top of the widget rather than next to it.

    The current implementation is something along the lines of:

    Qt Code:
    1. class NestedMainWidget(QWidget):
    2. def __init__(self, parent=None):
    3. QWidget.__init__(self, parent)
    4. self.main_widget = MainWidget(self)
    5. self.scrollbar = QScrollBar(Qt.Horizontal, self)
    6. self.box = QVBoxLayout()
    7. self.box.addWidget(self.canvas)
    8. self.box.addWidget(self.scrollbar)
    9. self.scrollbar.hide()
    10. self.setLayout(self.box)
    11. ...
    To copy to clipboard, switch view to plain text mode 

    The show/hide logic will then show/hide the scroll bar according to where the mouse position. This works fine. But obviously with this implementation the scroll bar will be shown next to the main widget, i.e., the main widget will be shrunk vertically to show the scroll bar.

    How can I have the scroll bar to show on top of the main widget instead?

    (The behavior I'm after is the scroll bar hiding that OS X Lion implements btw.)

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How can I show/hide a QScrollBar on top of a widget instead of next to it?

    Don't put the scroll bar in the layout if you don't want the layout to adjust when you make it visible. You will need to manually size and position the scroll bar when you make it visible.

Similar Threads

  1. Replies: 10
    Last Post: 20th April 2015, 23:24
  2. Replies: 4
    Last Post: 2nd October 2011, 01:20
  3. Replies: 2
    Last Post: 8th February 2011, 19:07
  4. MAC: Getting Dock widget show/hide events
    By jay in forum Qt Programming
    Replies: 3
    Last Post: 31st May 2010, 09:07
  5. QScrollbar show scratching on scrolling on any widget
    By santosh.kumar in forum Qt Programming
    Replies: 0
    Last Post: 21st April 2008, 06:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.