Results 1 to 13 of 13

Thread: Moving scroll bar inside QScroll Area

  1. #1
    Join Date
    Oct 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Moving scroll bar inside QScroll Area

    Hi,

    I need to use a custom scroll bar for the QScrollArea widget which I am setting using the setVerticalScrollBar() member function. However, my custom scroll bar is showing up complete, it's being cut. The custom scroll bar has a width of 48px.

    MyScrollBar::MyScrollBar(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MyScrollBar)
    {
    scrollWidget = new ScrollWidget(this);
    scrollBar = new ScrollBar(Qt::Vertical, this);

    ui->setupUi(this);
    scrollBar->setMaximumWidth(46);
    scrollBar->setMinimumWidth(46);
    ui->scrollArea->setVerticalScrollBar(scrollBar);

    //ui->scrollArea->widget()->show();
    }

    See image below..

    ScrollBarPushed.PNG

    NormalScroll.PNG

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Moving scroll bar inside QScroll Area

    I think that if the bar is wider than the standard bar, you will need to adjust the scroll area viewport's contents margins accordingly and maybe also position the new bar yourself inside a reimplemented resizeEvent.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Moving scroll bar inside QScroll Area

    Thanks for the response. Could you elaborate on this : scroll area viewport's contents margins

    Is the viewport a subcontrol of the scrollArea widget. I am unable to get any information on the subcontrols that belong to QScrollArea.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Moving scroll bar inside QScroll Area

    Look at QAbstractScrollArea api.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Moving scroll bar inside QScroll Area

    I tried setting the margins using the setViewportMargins(), but it didn't work.

    ScrollArea::ScrollArea(QWidget *parent, QScrollBar *scrollbar) :
    QScrollArea(parent)
    {
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    setVerticalScrollBar(scrollbar);
    setViewportMargins(0, 0, 50, 0);
    }

    I am not familiar with the resize event so I have not tried it yet. I just wanted to make sure if I was on the correct path.

    Scroll.PNG

  6. #6
    Join Date
    Oct 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Moving scroll bar inside QScroll Area

    Tried to add the setViewportMargins in the resize event function, but that didn't work either. Any other hints? I've looked everywhere but haven't found anything. Looks like I might have to create a custom scroll bar and link the signals to the scrollarea widget.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Moving scroll bar inside QScroll Area

    How does "doesn't work" manifest itself?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Oct 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Moving scroll bar inside QScroll Area

    The scroll bar is still clipped off. I am unable to move it's position within QScrollArea Widget.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Moving scroll bar inside QScroll Area

    Quote Originally Posted by gmahan View Post
    The scroll bar is still clipped off. I am unable to move it's position within QScrollArea Widget.
    Can we see the code you have written to achieve this?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Oct 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Moving scroll bar inside QScroll Area

    #include "scrollarea.h"

    ScrollArea::ScrollArea(QWidget *parent, QScrollBar *scrollbar) :
    QScrollArea(parent)
    {
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    setVerticalScrollBar(scrollbar);
    setViewportMargins(50, 50, 50, 50);
    }

    ScrollArea::~ScrollArea()
    {

    }

    void ScrollArea::resizeEvent(QResizeEvent *event)
    {
    setViewportMargins(0, 0, 50, 0);

    QScrollArea::resizeEvent(event);
    }

    #include "scrollbar.h"

    ScrollBar::ScrollBar(Qt::Orientation orientation, QWidget *parent):
    QScrollBar(orientation, parent)
    {
    setMaximumWidth(48);
    setMinimumWidth(48);

    /* Center Body */
    this->setStyleSheet(QString("QScrollBar:vertical {"
    "background: #333333;"
    "margin: 46px 0 46px 0;"
    "}"
    /*Slider*/
    "QScrollBar::handle:vertical {"
    "border: none;"
    "background: #4b4b4b;"
    "}"

    /* Down button */
    "QScrollBar::add-line:vertical {"
    "background: none;"
    "height: 48px;"
    "subcontrol-position: bottom;"
    "subcontrol-origin: margin;"
    "}"
    /*Up-button*/
    "QScrollBar::sub-line:vertical {"
    "background: none;"
    "height: 48px;"
    "subcontrol-position: top;"
    "subcontrol-origin: margin;"
    "}"

    /* add-page, sub-page subcontrol*/
    "QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {"
    "background: none;"
    "}"

    /*up arrow normal state*/
    "QScrollBar::up-arrow:vertical {"
    "image: url(:/Images/scroll-uparrow);"
    "width: 48px;"
    "height: 46px;"
    "}"

    /* down arrow normal state*/
    "QScrollBar::down-arrow:vertical {"
    "image: url(:/Images/scroll-downarrow);"
    "width: 48px;"
    "height: 46px;"
    "}"

    /* up arrow pressed*/
    "QScrollBar::up-arrow:vertical:pressed {"
    "image: url(:/Images/scroll-uparrow-hit);"
    "width: 48px;"
    "height: 46px;"
    "}"

    /* down arrow pressed*/
    "QScrollBar::down-arrow:vertical:pressed {"
    "image: url(:/Images/scroll-downarrow-hit);"
    "width: 48px;"
    "height: 46px;"
    "}"));


    }

    ScrollBar::~ScrollBar()
    {

    }

    #include "scrollbar.h"
    #include "myscrollbar.h"
    #include "scrollwidget.h"
    #include "scrollarea.h"

    #include <QApplication>
    #include <QVBoxLayout>
    #include <QSize>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    QWidget *mainWindow = new QWidget;
    ScrollBar *scrollBar = new ScrollBar(Qt::Vertical, mainWindow);
    ScrollArea *scrollArea = new ScrollArea(mainWindow, scrollBar);

    QVBoxLayout *layout = new QVBoxLayout;

    mainWindow->setWindowTitle("Scroll");
    layout->addWidget(scrollArea);
    mainWindow->setLayout(layout);
    mainWindow->show();

    return a.exec();
    }



    Sorry, for the annoying text format. What is the tag to insert code.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Moving scroll bar inside QScroll Area

    Ok, but in the resize event you were supposed to reposition the scrollbar to where you want it to be. Calling the base class implementation will position the bar exactly the same way as originally.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Oct 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Moving scroll bar inside QScroll Area

    Hmm, I guess that is the part I am tripping. What function call do you use to reposition the bar?

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Moving scroll bar inside QScroll Area

    Setter of QWidget::geometry property.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Scroll Area inside Dock Widget
    By saransiva_ps in forum Qt Programming
    Replies: 2
    Last Post: 6th August 2013, 06:35
  2. Increase the maximum limit of Qscroll area
    By anupam in forum Qt Programming
    Replies: 7
    Last Post: 18th June 2013, 04:20
  3. Replies: 8
    Last Post: 2nd February 2012, 19:52
  4. Scroll bars in scroll area not comming in scroll area
    By aurora in forum Qt Programming
    Replies: 3
    Last Post: 4th January 2012, 06:50
  5. About QScroll Area
    By franco.amato in forum Qt Programming
    Replies: 16
    Last Post: 26th January 2010, 22:59

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.