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. How to get status of QScrollBar ?
Qt 6.11 is out! See what's new in the release blog

How to get status of QScrollBar ?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 577 Views 1 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.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1

    I am writing a image viewer.
    When need scrollbar Key_Left and Key_Right move horizontal scrollbar.
    When do not need scrollbar Key_Left and Key_Right run lastImage and nextImage.

    connect(new QShortcut(QKeySequence(Qt::Key_Left),this), SIGNAL(activated()),this, SLOT(lastImage()));
    
    void MainWindow::lastImage()
    {
        if ( !ui->scrollArea->horizontalScrollBar()->isNeeded && ui->scrollArea->verticalScrollBar()->isNeeded() ) { // How to write here ?
            int id = index - 1;
            if (id > -1) {
                path = fileInfoList.at(id).absoluteFilePath();
                loadImage(path);
                index = id;
            }
        }else{
            ui->scrollArea->horizontalScrollBar()->setValue(ui->scrollArea->horizontalScrollBar()->value() - 20);
        }
    }
    

    https://github.com/sonichy

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What should be the logic behind isNeeded ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • sonichyS Offline
        sonichyS Offline
        sonichy
        wrote on last edited by sonichy
        #3

        Solved !

        if (ui->scrollArea->horizontalScrollBar()->visibleRegion().isEmpty()) {
            ...
        }
        

        https://github.com/sonichy

        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