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. Problem when i scroll to maximum values

Problem when i scroll to maximum values

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 986 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.
  • S Offline
    S Offline
    salvador
    wrote on last edited by
    #1

    Hello,
    i have imlemented already this "screenshot1":https://www.dropbox.com/s/vnoyunb3byroztl/screenshot1.png
    I have a problem when i scroll (horizontally or vertically) to maximum values, this is how it looks
    "sceenshot2":https://www.dropbox.com/s/bxccieps66a15mm/prtscreen1.png
    As you see the last row is not totally aligned.

    Some snippset of code:
    the initialization of the scrollbars
    @void VDatagridView::scrollBarInit()
    {
    int visibleRows = calcVerticalGeometry();
    int verticalPageStep = visibleRows;
    int verticalMax = ui->verticalTableView->verticalScrollBar()->maximum();
    ui->verticalScrollBar->setMinimum(0);
    ui->verticalScrollBar->setSingleStep(1);
    ui->verticalScrollBar->setPageStep(verticalPageStep);
    ui->verticalScrollBar->setMaximum(verticalMax);

    int visibleColumns = calcHorizontalGeometry();
    int horizontalPagestep = visibleColumns;
    int horizontalMax = ui->horizontalTableView->horizontalScrollBar()->maximum();
    ui->horizontalScrollBar->setMaximum(0);
    ui->horizontalScrollBar->setSingleStep(1);
    ui->horizontalScrollBar->setPageStep(horizontalPagestep);
    ui->horizontalScrollBar->setMaximum(horizontalMax+1);
    }@
    This function called when i start the programm and when the window is resized

    The function that draws the grid in the viewport
    @void VDatagridView::drawGrid()
    {
    int verticalSValue = min(ui->verticalScrollBar->value(), getMaxSVerValue());
    int columns = calcHorizontalGeometry();
    int rows = calcVerticalGeometry();
    _dataModel = new QStandardItemModel(rows, columns, this);

    ui->tableView->verticalHeader()->hide();
    ui->tableView->horizontalHeader()->hide();
    ui->tableView->setModel(_dataModel);
    if (verticalSValue < getMaxSVerValue())
    {
    for ( int i = 0; i < rows; i++)
    {
    ui->tableView->setRowHeight(i, (ui->verticalTableView->rowHeight(verticalSValue+i)));
    }

    }
    else
    {
    for ( int i = 0; i < rows; i++)
    {
    ui->tableView->setRowHeight(i, (ui->verticalTableView->rowHeight(verticalSValue+i)));
    }

    }

    int horizontalSValue = min(ui->horizontalScrollBar->value(), getMaxSHorValue());

    if (horizontalSValue < getMaxSHorValue())
    {
    for ( int i = 0; i < columns; i++)
    {
    ui->tableView->setColumnWidth(i, (ui->horizontalTableView->columnWidth(horizontalSValue+i)));
    }

    }
    else
    {
    for ( int i = 0; i < columns; i++)
    {
    ui->tableView->setColumnWidth(i, (ui->horizontalTableView->columnWidth(horizontalSValue+i)));
    }

    }
    }@
    The else case is when the scrollbar has the maximum vlaue. I haven't write something different right now because i don't know if this is the problem and also i don't know what should i change.

    Also the function tha drawGrid() uses
    @int VDatagridView::calcVerticalGeometry()
    {
    int count=0, freeSpace;
    freeSpace = ui->verticalTableView->geometry().height();

    for(;;)
    {
    freeSpace -= ui->verticalTableView->rowHeight( count++ + min( ui->verticalScrollBar->value() ,getMaxSVerValue() ));

    if ( freeSpace <=0 || count>100 )
    {
    
      return count;
    }
    

    }
    }@

    @int VDatagridView::calcHorizontalGeometry()
    {
    int count = 0;
    int freeSpace = ui->horizontalTableView->geometry().width();

    int scrollBarIndex = ui->horizontalTableView->horizontalScrollBar()->value();

    for(;;)
    {
    freeSpace -= ui->horizontalTableView->columnWidth( count + scrollBarIndex );
    count++;

    if ( freeSpace <= 0 || count > 100 )
    {
      return count;
    }
    

    }

    }@

    horizontalTableView is the table with the dates, verticalTableView is the one on the left and tableView is the grid.

    Any ideas?
    Thanks in advance!

    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