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. QAbstractScrollArea::setHorizontalBarPolicy updates the listWidget in bad Way
Forum Updated to NodeBB v4.3 + New Features

QAbstractScrollArea::setHorizontalBarPolicy updates the listWidget in bad Way

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 193 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.
  • L Offline
    L Offline
    leonardoMB
    wrote on last edited by
    #1
    listWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    

    Currently my code is like this and and I Have a splitter, but if I move the split to the point that I don't need more the scroll, the list is updated in the sense that if I were at the line 450, the list goes up to the line 1. How avoid such behavior?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by ChrisW67
      #2

      The widget below does not display the behaviour you describe.

      #include "widget.h"
      
      #include <QListWidget>
      #include <QSplitter>
      #include <QTextEdit>
      #include <QVBoxLayout>
      
      Widget::Widget(QWidget *parent)
          : QWidget(parent)
      {
      
          QListWidget *list = new QListWidget(this);
          list->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);  
              // ^^^ this is the default in many styles anyway
          QString entry;
          for (int row = 0; row < 10; ++row) {
              entry.append("word ");
              list->addItem(QString("Row %1 %2").arg(row).arg(entry));
          }
      
          QTextEdit *edit = new QTextEdit(this);
      
          QSplitter *splitter = new QSplitter(this);
          splitter->addWidget(list);
          splitter->addWidget(edit);
      
          QVBoxLayout *layout = new QVBoxLayout(this);
          layout->addWidget(splitter);
      }
      
      Widget::~Widget()
      {
      }
      
      

      Before

      Screenshot_20220619_164029.png
      After stretching horizontally
      Screenshot_20220619_164042.png
      Row 2 stays where it was after the horizontal scroll bar disappears.
      [Edit: wrong screen shots in original post]

      L 1 Reply Last reply
      2
      • C ChrisW67

        The widget below does not display the behaviour you describe.

        #include "widget.h"
        
        #include <QListWidget>
        #include <QSplitter>
        #include <QTextEdit>
        #include <QVBoxLayout>
        
        Widget::Widget(QWidget *parent)
            : QWidget(parent)
        {
        
            QListWidget *list = new QListWidget(this);
            list->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);  
                // ^^^ this is the default in many styles anyway
            QString entry;
            for (int row = 0; row < 10; ++row) {
                entry.append("word ");
                list->addItem(QString("Row %1 %2").arg(row).arg(entry));
            }
        
            QTextEdit *edit = new QTextEdit(this);
        
            QSplitter *splitter = new QSplitter(this);
            splitter->addWidget(list);
            splitter->addWidget(edit);
        
            QVBoxLayout *layout = new QVBoxLayout(this);
            layout->addWidget(splitter);
        }
        
        Widget::~Widget()
        {
        }
        
        

        Before

        Screenshot_20220619_164029.png
        After stretching horizontally
        Screenshot_20220619_164042.png
        Row 2 stays where it was after the horizontal scroll bar disappears.
        [Edit: wrong screen shots in original post]

        L Offline
        L Offline
        leonardoMB
        wrote on last edited by
        #3

        @ChrisW67 You are right, I was setting an ItemUpdate after the Splitter resize through setResizeMode(QListWidget::Adjust), it was causing my bad behavior, after removing no problem was encountered

        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