Results 1 to 13 of 13

Thread: Moving scroll bar inside QScroll Area

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.


  3. #3
    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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
  •  
Qt is a trademark of The Qt Company.