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. ScrollBar isn't placing at the current position
Forum Update on Monday, May 27th 2025

ScrollBar isn't placing at the current position

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 1.5k Views
  • 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.
  • D Offline
    D Offline
    Dimple
    wrote on last edited by Dimple
    #1

    Hi guys ,,
    can anybody please help me to fix this issue ,,
    i upload image below ,,scrollbar automatically shows when the list has too many items but issue is when one user is online or offline, scroll of QListWidget is moving to top ,,
    If I set(drag& drop) scroll to middle and one user become online, scroll is keeping current position ??
    scrollbar has be to set at the setted place only how to do it??
    0_1548444995392_sh.png

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dimple
      wrote on last edited by
      #7

      @J-Hilk
      Thanks for ur solution ,,issue fixed

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

        Hi,

        What are you doing when the user changes its status ?

        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
        1
        • D Offline
          D Offline
          Dimple
          wrote on last edited by
          #3

          @SGaist thanks for ur reply
          ex:when i set scroll to the middle ,,if some one user comes to the online(already integrated API's to show green colour when user runs our app(below of the image small circle is there know that one)) automatically that scroll goes to the top so ,i want to set it to current postion ??
          just assume u are a 1st person already in online now i ll scroll down scrollbar to middle then im a second person i ll come to the online ,that scrollbar shouldnot move (it should be at the middle only)??

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

            I understood the idea. What I'm asking is what are you doing code wise that makes your scrollbar move when one user changes its status.

            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
            2
            • D Offline
              D Offline
              Dimple
              wrote on last edited by
              #5

              void ContactsPage::updateContactList()
              {
              ui->list_contacts->clear();

              QList<Contact*> totalList = DataManager::getInstance()->getContacts();
              for(int i = 0; i < totalList.size(); i++)
              {
                  Contact* pContact = totalList[i];
                  switch(m_activeTab)
                  {
                      case TCTT_ALL:
                          if(pContact->getType() == Contact::TYPE_ACCOUNT)
                          {
                              QListWidgetItem* pListWidgetItem = new QListWidgetItem(ui->list_contacts);
                              ui->list_contacts->addItem(pListWidgetItem);
                              AccountCell* pAccountItem = new AccountCell(TCTT_ALL, pContact, this);
                              pListWidgetItem->setSizeHint(QSize(332, 64));
                              ui->list_contacts->setItemWidget(pListWidgetItem, pAccountItem);
              

              i added only these lines of code how do i set scrollbar even i haven't taken scrollbar ,automatically it shows when more items are added ??

              J.HilkJ 1 Reply Last reply
              0
              • D Dimple

                void ContactsPage::updateContactList()
                {
                ui->list_contacts->clear();

                QList<Contact*> totalList = DataManager::getInstance()->getContacts();
                for(int i = 0; i < totalList.size(); i++)
                {
                    Contact* pContact = totalList[i];
                    switch(m_activeTab)
                    {
                        case TCTT_ALL:
                            if(pContact->getType() == Contact::TYPE_ACCOUNT)
                            {
                                QListWidgetItem* pListWidgetItem = new QListWidgetItem(ui->list_contacts);
                                ui->list_contacts->addItem(pListWidgetItem);
                                AccountCell* pAccountItem = new AccountCell(TCTT_ALL, pContact, this);
                                pListWidgetItem->setSizeHint(QSize(332, 64));
                                ui->list_contacts->setItemWidget(pListWidgetItem, pAccountItem);
                

                i added only these lines of code how do i set scrollbar even i haven't taken scrollbar ,automatically it shows when more items are added ??

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by J.Hilk
                #6

                hi @Dimple

                this is you problem

                ui->list_contacts->clear();

                you completely clear the listwidget and add all items anew, and as a result of that the scrollbar gets reset each time you call updateContactList

                either work with add and remove item or save the scrollbar position before calling clear and set it after wards.

                int tempPos = ui->list_contacts->verticalScrollBar()->value();
                
                ui->list_contacts->clear();
                ....
                ...
                
                ui->list_contacts->verticalScrollBar()->setValue(tempPos);
                
                

                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                2
                • D Offline
                  D Offline
                  Dimple
                  wrote on last edited by
                  #7

                  @J-Hilk
                  Thanks for ur solution ,,issue fixed

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    Dimple
                    wrote on last edited by
                    #8

                    @J-Hilk
                    just now i noticed that onemore issue i'am getting as u said if i'am going to add code what happens Now we are refreshing all list items,So, I wanted to update only changed items, not all,
                    With current solution, i can go now but if cell count is over than 100, we can feel small delay , so correct solution is to update only changed cells??

                    J.HilkJ 1 Reply Last reply
                    0
                    • D Dimple

                      @J-Hilk
                      just now i noticed that onemore issue i'am getting as u said if i'am going to add code what happens Now we are refreshing all list items,So, I wanted to update only changed items, not all,
                      With current solution, i can go now but if cell count is over than 100, we can feel small delay , so correct solution is to update only changed cells??

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #9

                      @Dimple said in ScrollBar isn't placing at the current position:

                      With current solution, i can go now but if cell count is over than 100, we can feel small delay , so correct solution is to update only changed cells??

                      yes, but that's also more a bandaid as well. For a model that encompasses so many potential items, I would suggest looking into QListView and a proper Delegate&Model for it. Will make your live easier in the long run.


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        Dimple
                        wrote on last edited by
                        #10

                        @J-Hilk thanks for ur reply
                        u mean instead of QListWidget to use QListView ?? i didn't get ??

                        J.HilkJ 1 Reply Last reply
                        0
                        • D Dimple

                          @J-Hilk thanks for ur reply
                          u mean instead of QListWidget to use QListView ?? i didn't get ??

                          J.HilkJ Offline
                          J.HilkJ Offline
                          J.Hilk
                          Moderators
                          wrote on last edited by
                          #11

                          @Dimple

                          Yes, QListWidgets is a specialized form of a QListView.

                          I you move from from QListWidget to QListView, you'll have to implement your own (data)model and delegate.

                          It is more to write/code but will be faster and easier to manage, than using QListWidget and addItem(QListWidgetItem *)


                          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                          Q: What's that?
                          A: It's blue light.
                          Q: What does it do?
                          A: It turns blue.

                          1 Reply Last reply
                          0
                          • D Offline
                            D Offline
                            Dimple
                            wrote on last edited by Dimple
                            #12

                            can't i do using QListWidget to update only changed cells ?

                            J.HilkJ 1 Reply Last reply
                            0
                            • D Dimple

                              can't i do using QListWidget to update only changed cells ?

                              J.HilkJ Offline
                              J.HilkJ Offline
                              J.Hilk
                              Moderators
                              wrote on last edited by
                              #13

                              @Dimple
                              sure you can, QListWidget offers you functions to remove add individual Items
                              for example: http://doc.qt.io/qt-5/qlistwidget.html#takeItem

                              I'm just saying, the better way would be to switch to a QListView and a proper model. I know I'm often guilty of using QListWidget myself, as it's easier and faster to create something visual.


                              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                              Q: What's that?
                              A: It's blue light.
                              Q: What does it do?
                              A: It turns blue.

                              1 Reply Last reply
                              1

                              • Login

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