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 add scroll bar action
Forum Updated to NodeBB v4.3 + New Features

How to add scroll bar action

Scheduled Pinned Locked Moved Solved General and Desktop
qt5.8.0qt 5.7scroll barscrolling
12 Posts 3 Posters 4.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.
  • K Kinesis
    9 Jul 2018, 06:20

    I want to add scroll bar that can be scrolled down and up until the top or bottom of my list widget . I already add the scroll bar but not the action.How can I add action of my scroll bar.I would appreciate any answers.
    Here is my code: mainwindow.cpp

        ui->listWidget_2->setFlow(QListView::LeftToRight);
        ui->listWidget_2->setMinimumSize(1000,740);
        ui->listWidget_2->setGridSize(QSize(1200, 410));
        ui->listWidget_2->setResizeMode(QListView::Adjust);
        ui->listWidget_2->setViewMode(QListView::ListMode);
        ui->listWidget_2->setWrapping(true);
        
        
        
        
        
        ui->listWidget_image->setFlow(QListView::LeftToRight);
        // ui->listWidget_image->setMinimumSize(1000,340);
        ui->listWidget_image->setGridSize(QSize(380, 360));
        ui->listWidget_image->setResizeMode(QListView::Adjust);
        ui->listWidget_image->setViewMode(QListView::ListMode);
        //ui->listWidget_image->setViewMode(QListWidget::IconMode);
        //ui->listWidget_image->setIconSize(QSize(400,360));
        // ui->listWidget_image->setResizeMode(QListWidget::Adjust);
        ui->listWidget_image->setWrapping(true);
        
        
        
        ui->listWidget_read->setFlow(QListView::LeftToRight);
        //ui->listWidget_read->setMinimumSize(860,380);
        ui->listWidget_read->setGridSize(QSize(380, 360));
        ui->listWidget_read->setResizeMode(QListView::Adjust);
        ui->listWidget_read->setViewMode(QListView::ListMode);
        ui->listWidget_read->setWrapping(true);
        auto    item = new QListWidgetItem("", ui->listWidget_2);
        auto    widget = new QWidget;
        auto    vb = new QVBoxLayout;
        auto    hb = new QHBoxLayout;
        vb->addWidget(ui->pushButton);
        
        
        vb->addWidget(ui->listWidget_image);
        vb->addWidget(ui->listWidget_read);
        hb->addLayout(vb);
        hb->addWidget(ui->verticalScrollBar);
        widget->setLayout(hb);
        widget->setMinimumSize(1200,730);
        ui->listWidget_2->setItemWidget(item,widget);
        
        
        QDir directory = QFileDialog::getExistingDirectory(this, tr("Open Directory"),"/home",
                                                           
                                                           QFileDialog::ShowDirsOnly| QFileDialog::DontResolveSymlinks);
        
        
        
        
        directory.setNameFilters({"*.log", "*.txt" , "*.sh" , "*.yml"});
        
        for(const QFileInfo & finfo: directory.entryInfoList()){
            
            m_textEdit = new QTextEdit;
            m_textEdit -> setReadOnly(true);
            QFile data(finfo.absoluteFilePath()) ;
            data.open(QIODevice::ReadOnly);
            QTextStream stream(&data);
            QString content = stream.readAll();
            data.close();
            
            m_textEdit->setText(content);
            auto    item = new QListWidgetItem("", ui->listWidget_read);
            auto    widget = new QWidget;
            auto    label = new QLabel(finfo.fileName());
            auto    vb = new QVBoxLayout;
            
            vb->addWidget(label);
            vb->addWidget(m_textEdit);
            
            widget->setLayout(vb);
            widget->setMinimumSize(340, 340);
            ui->listWidget_read->setItemWidget(item, widget);
            
            
            
        }
        
        
        
        
        directory.setNameFilters({"*.mp4" , "*.avi" , "*.flv" , "*.mwv"});
        
        for(const QFileInfo & finfo: directory.entryInfoList()){
            QMediaPlayer *mediaPlayer = new QMediaPlayer();
            mediaPlayer->setMedia(QUrl::fromLocalFile(finfo.absoluteFilePath()));
            videoItem = new QGraphicsVideoItem;
            videoItem->setSize(QSize(320,240));
            QGraphicsScene *scene = new QGraphicsScene(this);
            QGraphicsView *graphicsView = new QGraphicsView(scene);
            mediaPlayer->setVideoOutput(videoItem);
            
            QPushButton *m_playButton = new QPushButton();
            m_playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
            
            connect(m_playButton, &QAbstractButton::clicked, [mediaPlayer]() {
                switch (mediaPlayer->state()) {
                case QMediaPlayer::PlayingState:
                    mediaPlayer->pause();
                    break;
                default:
                    mediaPlayer->play();
                    break;
                }
            });
            
            
            connect(mediaPlayer, &QMediaPlayer::stateChanged, [m_playButton, this](QMediaPlayer::State state) {
                switch(state) {
                case QMediaPlayer::PlayingState:
                    m_playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause));
                    break;
                default:
                    m_playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
                    break;
                }
            });
            
            
            
            QSlider *m_positionSlider = new QSlider(Qt::Horizontal,this);
            m_positionSlider->setRange(0,mediaPlayer->duration() / 1000);
            
            
            connect(mediaPlayer, &QMediaPlayer::positionChanged ,[m_positionSlider, this](qint64 position){
                
                m_positionSlider->setValue(position);
            });
            
            connect(mediaPlayer, &QMediaPlayer::durationChanged ,[m_positionSlider, this](qint64 duration){
                
                m_positionSlider->setRange(0,duration);
            });
            
            
            connect(m_positionSlider ,&QAbstractSlider::sliderMoved, [mediaPlayer ,this] (int position){
                
                mediaPlayer->setPosition(position);
            });
            
            
            
            
            auto    item = new QListWidgetItem("", ui->listWidget_image);
            auto    widget = new QWidget;
            auto    label = new QLabel(finfo.fileName());
            auto    vb = new QVBoxLayout;
            
            QBoxLayout *controlLayout = new QHBoxLayout;
            controlLayout->setMargin(0);
            controlLayout->addWidget(m_playButton);
            controlLayout->addWidget(m_positionSlider);
            
            vb->addWidget(label);
            vb->addWidget(graphicsView);
            vb->addLayout(controlLayout);
            widget->setLayout(vb);
            widget->setMinimumSize(340, 340);
            ui->listWidget_image->setItemWidget(item,widget);
            player.append(mediaPlayer);
            scene->addItem(videoItem);
            
            
            
        }
    
    J Offline
    J Offline
    jsulm
    Lifetime Qt Champion
    wrote on 9 Jul 2018, 06:43 last edited by
    #2

    @Kinesis What action do you mean?

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    K 1 Reply Last reply 9 Jul 2018, 06:52
    0
    • J jsulm
      9 Jul 2018, 06:43

      @Kinesis What action do you mean?

      K Offline
      K Offline
      Kinesis
      wrote on 9 Jul 2018, 06:52 last edited by
      #3

      @jsulm
      I just need to scroll down or up to see the items . I can't see all of my items on the display because of the listWidget frame size .That's why I need to scroll down to see other items . I don't know how can I add scrolling action .

      J 1 Reply Last reply 9 Jul 2018, 06:59
      0
      • K Kinesis
        9 Jul 2018, 06:52

        @jsulm
        I just need to scroll down or up to see the items . I can't see all of my items on the display because of the listWidget frame size .That's why I need to scroll down to see other items . I don't know how can I add scrolling action .

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 9 Jul 2018, 06:59 last edited by
        #4

        @Kinesis said in How to add scroll bar action:

        I don't know how can I add scrolling action

        Like shown here: http://doc.qt.io/qt-5/qscrollarea.html

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        K 1 Reply Last reply 9 Jul 2018, 07:02
        0
        • J jsulm
          9 Jul 2018, 06:59

          @Kinesis said in How to add scroll bar action:

          I don't know how can I add scrolling action

          Like shown here: http://doc.qt.io/qt-5/qscrollarea.html

          K Offline
          K Offline
          Kinesis
          wrote on 9 Jul 2018, 07:02 last edited by
          #5

          @jsulm
          So , can I just add my listwidget on scrollarea ??

          J 1 Reply Last reply 9 Jul 2018, 07:03
          0
          • K Kinesis
            9 Jul 2018, 07:02

            @jsulm
            So , can I just add my listwidget on scrollarea ??

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 9 Jul 2018, 07:03 last edited by
            #6

            @Kinesis Sure, you can. Did you try?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            K 1 Reply Last reply 9 Jul 2018, 08:21
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 9 Jul 2018, 07:34 last edited by
              #7

              Hi,

              QListWidget already has scrollbars so why do you want to put it in a QScrollArea since it already provides that functionality ?

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

              K 1 Reply Last reply 9 Jul 2018, 07:56
              3
              • S SGaist
                9 Jul 2018, 07:34

                Hi,

                QListWidget already has scrollbars so why do you want to put it in a QScrollArea since it already provides that functionality ?

                K Offline
                K Offline
                Kinesis
                wrote on 9 Jul 2018, 07:56 last edited by
                #8

                @SGaist
                If so , how can I use these functionality?

                1 Reply Last reply
                0
                • J jsulm
                  9 Jul 2018, 07:03

                  @Kinesis Sure, you can. Did you try?

                  K Offline
                  K Offline
                  Kinesis
                  wrote on 9 Jul 2018, 08:21 last edited by aha_1980 7 Oct 2018, 04:19
                  #9

                  @jsulm
                  Thanks . I get it now. it's working :)

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 9 Jul 2018, 11:47 last edited by
                    #10

                    The scroll bars appear as soon as the content exceeds the size of the widget itself, unless you force the policy to always on.

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

                    K 1 Reply Last reply 10 Jul 2018, 11:13
                    2
                    • S SGaist
                      9 Jul 2018, 11:47

                      The scroll bars appear as soon as the content exceeds the size of the widget itself, unless you force the policy to always on.

                      K Offline
                      K Offline
                      Kinesis
                      wrote on 10 Jul 2018, 11:13 last edited by
                      #11

                      @SGaist
                      Ya, I know that the scroll area will appear like u said . But in my case it wont appear . That's why I need to use scrollarea.

                      1 Reply Last reply
                      1
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 10 Jul 2018, 21:27 last edited by
                        #12

                        Did you try to determine why they don't appear ?

                        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

                        11/12

                        10 Jul 2018, 11:13

                        • Login

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