Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QScrollArea signal or virtual function for "about to show scrollbar"
Forum Updated to NodeBB v4.3 + New Features

QScrollArea signal or virtual function for "about to show scrollbar"

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 2.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #1

    Hi
    Is it possible to catch a signal/virtual override to know when QScrollArea
    is about to show scrollbar?

    I want to disable the scrollbar and have buttons in
    top/bottom to show when normally the side scrollbar would appear.

    i have tried 
    
    class ScrollbarProxy : public QScrollBar {
      Q_OBJECT
    public:
      explicit ScrollbarProxy(QWidget* parent = nullptr);
    signals:
    
    public slots:
    
    protected:
      void changeEvent(QEvent* e) override {
        qDebug() << "changeEvent" << e->type();
      }
      void setVisible(bool visible) override {
        qDebug() << "setVisible" << visible ;    
      }
    };
    
    with 
    ui->scrollArea->setVerticalScrollBar( new ScrollbarProxy() );
    ui->scrollArea->setHorizontalScrollBar( new ScrollbarProxy() );
    

    In the hope i could just use setVisible but even i DONT call baseclass, the scrollbars
    are shown never the less?

    Also changeEvent did not show any info when scrollbars are shown.

    So any hints of how to intercept it if possible?

    alt text
    ( mockup )

    Basically i want to show the up/down buttons when ever the right side scrollbar would show it self.

    raven-worxR 1 Reply Last reply
    0
    • mrjjM mrjj

      Hi
      Is it possible to catch a signal/virtual override to know when QScrollArea
      is about to show scrollbar?

      I want to disable the scrollbar and have buttons in
      top/bottom to show when normally the side scrollbar would appear.

      i have tried 
      
      class ScrollbarProxy : public QScrollBar {
        Q_OBJECT
      public:
        explicit ScrollbarProxy(QWidget* parent = nullptr);
      signals:
      
      public slots:
      
      protected:
        void changeEvent(QEvent* e) override {
          qDebug() << "changeEvent" << e->type();
        }
        void setVisible(bool visible) override {
          qDebug() << "setVisible" << visible ;    
        }
      };
      
      with 
      ui->scrollArea->setVerticalScrollBar( new ScrollbarProxy() );
      ui->scrollArea->setHorizontalScrollBar( new ScrollbarProxy() );
      

      In the hope i could just use setVisible but even i DONT call baseclass, the scrollbars
      are shown never the less?

      Also changeEvent did not show any info when scrollbars are shown.

      So any hints of how to intercept it if possible?

      alt text
      ( mockup )

      Basically i want to show the up/down buttons when ever the right side scrollbar would show it self.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @mrjj

      1. scrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
      2. button->setVisible( scrollArea->verticalScrollBar()->minimum() < scrollArea->verticalScrollBar()->maximum() );
      3. connect the corresponding button to the scrollbar's triggerAction() method. Either with QAbstractSlider::SliderSingleStepAdd or QAbstractSlider::SliderPageStepAdd to scroll down.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      mrjjM 1 Reply Last reply
      4
      • raven-worxR raven-worx

        @mrjj

        1. scrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
        2. button->setVisible( scrollArea->verticalScrollBar()->minimum() < scrollArea->verticalScrollBar()->maximum() );
        3. connect the corresponding button to the scrollbar's triggerAction() method. Either with QAbstractSlider::SliderSingleStepAdd or QAbstractSlider::SliderPageStepAdd to scroll down.
        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        @raven-worx

        Ah, so there is no signal.

        The issue is when to call
        button->setVisible(xxx);

        I guess i must do in all cases where i insert/remove items,
        scale window etc.

        There really is no lesser hack-ish way ?

        Thank you

        raven-worxR 1 Reply Last reply
        0
        • mrjjM mrjj

          @raven-worx

          Ah, so there is no signal.

          The issue is when to call
          button->setVisible(xxx);

          I guess i must do in all cases where i insert/remove items,
          scale window etc.

          There really is no lesser hack-ish way ?

          Thank you

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @mrjj
          times to check (with the code i've provided) can be when

          1. QScrollArea receives QEvent::StyleChange or QEvent::LayoutRequest events
          2. the viewport widget resizes
          3. content widget resizes

          So you could use an event-filter, but make sure to make the check delayed.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          mrjjM 1 Reply Last reply
          0
          • raven-worxR raven-worx

            @mrjj
            times to check (with the code i've provided) can be when

            1. QScrollArea receives QEvent::StyleChange or QEvent::LayoutRequest events
            2. the viewport widget resizes
            3. content widget resizes

            So you could use an event-filter, but make sure to make the check delayed.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @raven-worx

            1: Are they recieved via changeEvent(QEvent* e) ?

            Thank you, i will try with eventfilter and see.

            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by VRonin
              #6

              can't you just use QAbstractSlider::rangeChanged signal?

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              5
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                Hi
                thx for both suggestions.
                rangeChanged works to some degree but fires 2 signal before even shown
                rangeChange 0 , 256
                rangeChange 0 , 0

                but Im pretty sure i can work something out if i can guess from values when it should be hidden again.

                This test code seems to do what i need and show hide the buttons as expected.

                void MainWindow::rangeChanged(int min, int max) {
                  
                  qDebug() << "rangeChange" << min << " , " << max;
                  
                  if (min < max)  {
                    ui->pushButton_4->show();
                    ui->pushButton_5->show();
                    qDebug() << "SHOW";
                  }
                
                  if  (min == 0 && max == 0) {
                    ui->pushButton_4->hide();
                    ui->pushButton_5->hide();
                    qDebug() << "HIDE";
                  }
                
                }
                
                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved