Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

scroll items by using touching (dragging) without using scrollbar in QScrollArea



  • Hi,
    I add dynamically buttons in QScrollArea. I want scroll up and down by using touch items (drag with mouse or touch screen). I do not want to scroll from vertical scroll bar so I hide it.

    How can I sove it?

    Thanks

    /QScrollArea *scrollArea = new QScrollArea( this );
        scrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
        scrollArea->setWidgetResizable( true );
        scrollArea->setGeometry( 10, 10, 200, 200 );
    
        QWidget *widget = new QWidget();
        scrollArea->setWidget( widget );
    
        QVBoxLayout *layout = new QVBoxLayout();
        widget->setLayout( layout );
    
        for (int i = 0; i < 10; i++)
        {
            QPushButton *button = new QPushButton( QString( "%1" ).arg( i ) );
            layout->addWidget( button );
        }
    

  • Lifetime Qt Champion

    Hi
    And welcome to the forums.
    I made a combobox touch scroll able by
    QScroller::grabGesture(ui->combo->view()->viewport(),QScroller::LeftMouseButtonGesture);
    I assume you can do something like for scrollArea too.

    http://doc.qt.io/qt-5/qscroller.html



  • Thanks @mrjj .
    It works.


Log in to reply