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 use scrollbar in QListView
Forum Updated to NodeBB v4.3 + New Features

How to use scrollbar in QListView

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.7k 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.
  • H Offline
    H Offline
    Heart_Blue
    wrote on last edited by
    #1

    @ QFileInfo fileinfo = QFileInfo(fileName);

    model->setRootPath(fileinfo.absoluteDir().absolutePath());
    model->setReadOnly(true);

    ui->listView->setModel(model);
    ui->listView->setRootIndex(model->setRootPath(fileinfo.absoluteDir().absolutePath()));
    ui->listView->setCurrentIndex(model->index(fileinfo.absoluteFilePath()));
    ui->listView->scrollToBottom();
    @

    while i open a file, I want to use QListView to show all the files in this folder, and meanwhile, get the scrollbar scroll tho the file.

    But the scrollbar remain in the top when all the files showed. Then, when i open another file in this folder, the scrollbar work well.

    I debug to see how scrollToBottom() work, i find when i first open a file, the maximum value of the scrollbar remain ZERO.

    Is there any way, when i first load a file, the scrollbar will scroll to the file automatically.

    THX :D

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

      Hi and welcome to devnet,

      To change the folder, you need to call setRooIndex with the appropriate index

      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
      • H Offline
        H Offline
        Heart_Blue
        wrote on last edited by
        #3

        [quote author="SGaist" date="1407966298"]Hi and welcome to devnet,

        To change the folder, you need to call setRooIndex with the appropriate index[/quote]

        thx
        but I have opened the folder correctly, but the scrollbar doesn't work well, as it doesn't scroll to the correct position, it still remain the top,

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

          That's strange, what version of Qt are you using ? On what OS ?

          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
          • H Offline
            H Offline
            Heart_Blue
            wrote on last edited by
            #5

            [quote author="SGaist" date="1408487317"]That's strange, what version of Qt are you using ? On what OS ?[/quote]
            Thx, i have solved it recently.

            This is because when i use
            @listView->setModel(model)@
            , the model is not set immediately. I just find it by debugging setModel() :D.

            Then i find this singal of Q***Model
            @void layoutChanged();@
            this signal can be used here, but i think this is not the best solution. as before the model is completely loaded, the signal is emitted several times.

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

              Indeed ! Detail I forgot, the QFileSystemModel is threaded

              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

              • Login

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