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. Scrolling hint PositionAtBottom not working as expected
Forum Updated to NodeBB v4.3 + New Features

Scrolling hint PositionAtBottom not working as expected

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 373 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.
  • P Offline
    P Offline
    Phil K
    wrote on last edited by Phil K
    #1

    Using a table view or a table widget, I cannot seem to scrollTo an item index such that the row is placed at the bottom of the viewport. Is there a workaround I can use?

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
    {
        const int kRows = 100;
        QHBoxLayout *layout = new QHBoxLayout();
        QWidget *central = new QWidget();
        table = new QTableWidget(kRows, 1);
        table->verticalHeader()->setVisible(false);
        QTableWidgetItem *header = new QTableWidgetItem("ROWS");
        table->setHorizontalHeaderItem(0, header);
        for (int i = 0; i < kRows; ++i) {
            QTableWidgetItem *item = new QTableWidgetItem(QString("row %1").arg(i));
            table->setItem(i, 0, item);
        }
        layout->addWidget(table);
        central->setLayout(layout);
        setCentralWidget(central);
        setMinimumHeight(305);
        table->resizeRowsToContents();
        QModelIndex index = table->model()->index(50, 0);
        // this line below does not move row 50 to the bottom
        table->scrollTo(index, QAbstractItemView::PositionAtBottom);
    }
    

    Positioning an item using the top hint works as expected, i.e. that row appears at the top of the viewport.

    table->scrollTo(index, QAbstractItemView::PositionAtTop);
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What if you trigger the scrollTo after your widget has been shown ?

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

      P 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        What if you trigger the scrollTo after your widget has been shown ?

        P Offline
        P Offline
        Phil K
        wrote on last edited by
        #3

        @SGaist Yes, much better, thanks! I should have had that intution on visibility -- live and learn. Marking as resolved. -Phil

        void MainWindow::showEvent(QShowEvent *event)
        {
            QMainWindow::showEvent(event);
            QModelIndex index = table->model()->index(50, 0);
            table->scrollTo(index, QAbstractItemView::PositionAtBottom);
        }
        

        scrollTo_bottom.png )

        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