Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Vertical ScrollBar of QTableWidget not moving as expected



  • Hi,

    I am using QTableWidget for creating a table of 513 rows and 9 columns.
    Naturally, for seeing all the rows, I need to use Vertical ScrollBar of QTableWidget.

    I set the maximum, minimum, page step and single step ..

    ui->tableWidget->verticalScrollBar()->setMaximum(513);
    ui->tableWidget->verticalScrollBar()->setMinimum(0);
    ui->tableWidget->verticalScrollBar()->setSingleStep(1);
    ui->tableWidget->verticalScrollBar()->setPageStep(10);
    ui->tableWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);

    And then I am using an Up Push Button for moving Page up and Down Push Button for moving Page down.

    And for Down PB, this is the code:

    int scroll = ui->tableWidget->verticalScrollBar()->value();
    ui->tableWidget->verticalScrollBar()->setValue((scroll + 10));

    But this is not moving as expected.
    One observation I made is, maximum is automatically changed to 2 and page size to 512.

    Is there any more settings to do?


  • Lifetime Qt Champion

    Hi,

    Why are you setting the minimum and maximum value of the scrollbar ? These are usually calculated for your base on the model content.



  • Hi SGaist,

    Thank You for the reply.

    By default the maximum is 2 and page step is 512.

    So when I press Down key, ui->tableWidget->verticalScrollBar()->value() is changing from 0 to 2 only.
    This is equivalent to moving a single row only.

    This is the case, even after adding dummy contents in all the cells.

    I think maximum() is not calculated correctly. I am missing something...

    Any ideas...please


  • Lifetime Qt Champion

    Show your complete code, otherwise we can only do speculations.



  • Hi SGaist,

    Thank You for the reply and supporting.

    The full code is given below.

    form_Table() shall be executed in a while loop and Key_Up_Routine and Key_Down_Routine whenever keys are pressed.

    form_Table {

        QTableWidgetItem * Display_item_0_0 = new QTableWidgetItem("0");
        QTableWidgetItem * Display_item_0_1 = new QTableWidgetItem("1");
        QTableWidgetItem * Display_item_0_2 = new QTableWidgetItem("2");
        QTableWidgetItem * Display_item_0_3 = new QTableWidgetItem("3");
        QTableWidgetItem * Display_item_0_4 = new QTableWidgetItem("4");
        QTableWidgetItem * Display_item_0_5 = new QTableWidgetItem("5");
        QTableWidgetItem * Display_item_0_6 = new QTableWidgetItem("6");
        QTableWidgetItem * Display_item_0_7 = new QTableWidgetItem("7");
        QTableWidgetItem * Display_item_0_8 = new QTableWidgetItem("8");
        QTableWidgetItem * Display_item_513_0 = new QTableWidgetItem("0");
        QTableWidgetItem * Display_item_513_1 = new QTableWidgetItem("1");
        QTableWidgetItem * Display_item_513_2 = new QTableWidgetItem("2");
        QTableWidgetItem * Display_item_513_3 = new QTableWidgetItem("3");
        QTableWidgetItem * Display_item_513_4 = new QTableWidgetItem("4");
        QTableWidgetItem * Display_item_513_5 = new QTableWidgetItem("5");
        QTableWidgetItem * Display_item_513_6 = new QTableWidgetItem("6");
        QTableWidgetItem * Display_item_513_7 = new QTableWidgetItem("7");
        QTableWidgetItem * Display_item_513_8 = new QtableWidgetItem("8");
    

    .........
    .........
    .........

                QTableWidgetItem * Display_item_513_0 = new QTableWidgetItem("0");
        QTableWidgetItem * Display_item_513_1 = new QTableWidgetItem("1");
        QTableWidgetItem * Display_item_513_2 = new QTableWidgetItem("2");
        QTableWidgetItem * Display_item_513_3 = new QTableWidgetItem("3");
        QTableWidgetItem * Display_item_513_4 = new QTableWidgetItem("4");
        QTableWidgetItem * Display_item_513_5 = new QTableWidgetItem("5");
        QTableWidgetItem * Display_item_513_6 = new QTableWidgetItem("6");
        QTableWidgetItem * Display_item_513_7 = new QTableWidgetItem("7");
        QTableWidgetItem * Display_item_513_8 = new QtableWidgetItem("8");
    
    
        ui->tableWidget->setGeometry(-2,40,804,15424);
        ui->tableWidget->horizontalHeader()->setDefaultSectionSize(80);
        ui->tableWidget->verticalHeader()->setDefaultSectionSize(30);
    
        ui->tableWidget->setRowCount(514);
        ui->tableWidget->setColumnCount(9);
    
    
        ui->tableWidget->setColumnWidth(0,80);
        ui->tableWidget->setColumnWidth(1,80);
        ui->tableWidget->setColumnWidth(2,80);
        ui->tableWidget->setColumnWidth(3,80);
        ui->tableWidget->setColumnWidth(4,80);
        ui->tableWidget->setColumnWidth(5,80);
        ui->tableWidget->setColumnWidth(6,80);
        ui->tableWidget->setColumnWidth(7,80);
        ui->tableWidget->setColumnWidth(8,80);
    
    
    
        QStringList horz_header;
        horz_header.clear();
        horz_header.append(“T1”);
        horz_header.append(“T2”);
        horz_header.append(“T3”);
        horz_header.append(“T4”);
        horz_header.append(“T5”);
        horz_header.append(“T6”);
        horz_header.append(“T7”);
        horz_header.append(“T8”);
        horz_header.append(“T9”);
        ui->tableWidget->setHorizontalHeaderLabels(horz_header);
    
        QStringList vert_header;
        vert_header.clear();
        vert_header.append("P1");
        vert_header.append("P2");
        vert_header.append("P3");
        vert_header.append("P4");
    
        ui->tableWidget->setVerticalHeaderLabels(vert_header);
        ui->tableWidget->horizontalHeader()->setVisible(true);
        ui->tableWidget->verticalHeader()->setVisible(true);
        ui->tableWidget-setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
        ui->tableWidget->setAutoScroll(false);
    
    
        ui->tableWidget->setItem(0,0,Display_item_0_0);
        ui->tableWidget->setItem(0,1,Display_item_0_1);
        ui->tableWidget->setItem(0,2,Display_item_0_2);
        ui->tableWidget->setItem(0,3,Display_item_0_3);
        ui->tableWidget->setItem(0,4,Display_item_0_4);
        ui->tableWidget->setItem(0,5,Display_item_0_5);
        ui->tableWidget->setItem(0,6,Display_item_0_6);
        ui->tableWidget->setItem(0,7,Display_item_0_7);
        ui->tableWidget->setItem(0,8,Display_item_0_8);
        ui->tableWidget->setItem(1,0,Display_item_1_0);
        ui->tableWidget->setItem(1,1,Display_item_1_1);
        ui->tableWidget->setItem(1,2,Display_item_1_2);
        ui->tableWidget->setItem(1,3,Display_item_1_3);
        ui->tableWidget->setItem(1,4,Display_item_1_4);
        ui->tableWidget->setItem(1,5,Display_item_1_5);
        ui->tableWidget->setItem(1,6,Display_item_1_6);
        ui->tableWidget->setItem(1,7,Display_item_1_7);
        ui->tableWidget->setItem(1,8,Display_item_1_8);
    

    .........
    .........
    ..........

    ui->tableWidget_FDP->setItem(513,0,FDP_Display_item_513_0);
    ui->tableWidget_FDP->setItem(513,1,FDP_Display_item_513_1);
    ui->tableWidget_FDP->setItem(513,2,FDP_Display_item_513_2);
    ui->tableWidget_FDP->setItem(513,3,FDP_Display_item_513_3);
    ui->tableWidget_FDP->setItem(513,4,FDP_Display_item_513_4);
    ui->tableWidget_FDP->setItem(513,5,FDP_Display_item_513_5);
    ui->tableWidget_FDP->setItem(513,6,FDP_Display_item_513_6);
    ui->tableWidget_FDP->setItem(513,7,FDP_Display_item_513_7);
    ui->tableWidget_FDP->setItem(513,8,FDP_Display_item_513_8);

    ui->tableWidget_FDP->setSelectionBehavior(QAbstractItemView::SelectItems);
    ui->tableWidget_FDP->setSelectionMode(QAbstractItemView::SingleSelection);
    ui->tableWidget_FDP->setShowGrid(true);
    ui->tableWidget_FDP->horizontalHeader()->setSectionsMovable(true);
    ui->tableWidget_FDP->horizontalHeader()->setSectionsClickable(true);
    ui->tableWidget_FDP->horizontalHeader()->etSectionResizeMode(QHeaderView::Fixed);

    }

    Key_Up_Routine {

    int scroll;

    qDebug("current value = %d ", ui->tableWidget_FDP->verticalScrollBar()->value());
    scroll = ui->tableWidget_FDP->verticalScrollBar()->value();
    if(scroll >= 10) {
        ui->tableWidget_FDP->verticalScrollBar()->setValue((scroll - 10));
    }
    qDebug("new value = %d ", ui->tableWidget_FDP->verticalScrollBar()->value());
    

    }

    Key_Down_Routine {
    int scroll;

    qDebug("current value = %d ", ui->tableWidget_FDP->verticalScrollBar()->value());
    

    scroll = ui->tableWidget_FDP->verticalScrollBar()->value();
    ui->tableWidget_FDP->verticalScrollBar()->setValue((scroll + 10));
    qDebug("new value = %d ", ui->tableWidget_FDP->verticalScrollBar()->value());

    }



  • Hi,

    Some mistakes in previous mail. Please ignore that. The code sample I am using is as given below.

    form_Table {

        QTableWidgetItem * Display_item_0_0 = new QTableWidgetItem("0");
        QTableWidgetItem * Display_item_0_1 = new QTableWidgetItem("1");
        QTableWidgetItem * Display_item_0_2 = new QTableWidgetItem("2");
        QTableWidgetItem * Display_item_0_3 = new QTableWidgetItem("3");
        QTableWidgetItem * Display_item_0_4 = new QTableWidgetItem("4");
        QTableWidgetItem * Display_item_0_5 = new QTableWidgetItem("5");
        QTableWidgetItem * Display_item_0_6 = new QTableWidgetItem("6");
        QTableWidgetItem * Display_item_0_7 = new QTableWidgetItem("7");
        QTableWidgetItem * Display_item_0_8 = new QTableWidgetItem("8");
        QTableWidgetItem * Display_item_1_0 = new QTableWidgetItem("0");
        QTableWidgetItem * Display_item_1_1 = new QTableWidgetItem("1");
        QTableWidgetItem * Display_item_1_2 = new QTableWidgetItem("2");
        QTableWidgetItem * Display_item_1_3 = new QTableWidgetItem("3");
        QTableWidgetItem * Display_item_1_4 = new QTableWidgetItem("4");
        QTableWidgetItem * Display_item_1_5 = new QTableWidgetItem("5");
        QTableWidgetItem * Display_item_1_6 = new QTableWidgetItem("6");
        QTableWidgetItem * Display_item_1_7 = new QTableWidgetItem("7");
        QTableWidgetItem * Display_item_1_8 = new QtableWidgetItem("8");
    

    .........
    .........
    .........

                QTableWidgetItem * Display_item_513_0 = new QTableWidgetItem("0");
        QTableWidgetItem * Display_item_513_1 = new QTableWidgetItem("1");
        QTableWidgetItem * Display_item_513_2 = new QTableWidgetItem("2");
        QTableWidgetItem * Display_item_513_3 = new QTableWidgetItem("3");
        QTableWidgetItem * Display_item_513_4 = new QTableWidgetItem("4");
        QTableWidgetItem * Display_item_513_5 = new QTableWidgetItem("5");
        QTableWidgetItem * Display_item_513_6 = new QTableWidgetItem("6");
        QTableWidgetItem * Display_item_513_7 = new QTableWidgetItem("7");
        QTableWidgetItem * Display_item_513_8 = new QtableWidgetItem("8");
    
    
        ui->tableWidget->setGeometry(-2,40,804,15424);
        ui->tableWidget->horizontalHeader()->setDefaultSectionSize(80);
        ui->tableWidget->verticalHeader()->setDefaultSectionSize(30);
    
        ui->tableWidget->setRowCount(514);
        ui->tableWidget->setColumnCount(9);
    
    
        ui->tableWidget->setColumnWidth(0,80);
        ui->tableWidget->setColumnWidth(1,80);
        ui->tableWidget->setColumnWidth(2,80);
        ui->tableWidget->setColumnWidth(3,80);
        ui->tableWidget->setColumnWidth(4,80);
        ui->tableWidget->setColumnWidth(5,80);
        ui->tableWidget->setColumnWidth(6,80);
        ui->tableWidget->setColumnWidth(7,80);
        ui->tableWidget->setColumnWidth(8,80);
    
    
    
        QStringList horz_header;
        horz_header.clear();
        horz_header.append(“T1”);
        horz_header.append(“T2”);
        horz_header.append(“T3”);
        horz_header.append(“T4”);
        horz_header.append(“T5”);
        horz_header.append(“T6”);
        horz_header.append(“T7”);
        horz_header.append(“T8”);
        horz_header.append(“T9”);
        ui->tableWidget->setHorizontalHeaderLabels(horz_header);
    
        QStringList vert_header;
        vert_header.clear();
        vert_header.append("P1");
        vert_header.append("P2");
        vert_header.append("P3");
        vert_header.append("P4");
    
        ui->tableWidget->setVerticalHeaderLabels(vert_header);
        ui->tableWidget->horizontalHeader()->setVisible(true);
        ui->tableWidget->verticalHeader()->setVisible(true);
        ui->tableWidget-setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
        ui->tableWidget->setAutoScroll(false);
    
    
        ui->tableWidget->setItem(0,0,Display_item_0_0);
        ui->tableWidget->setItem(0,1,Display_item_0_1);
        ui->tableWidget->setItem(0,2,Display_item_0_2);
        ui->tableWidget->setItem(0,3,Display_item_0_3);
        ui->tableWidget->setItem(0,4,Display_item_0_4);
        ui->tableWidget->setItem(0,5,Display_item_0_5);
        ui->tableWidget->setItem(0,6,Display_item_0_6);
        ui->tableWidget->setItem(0,7,Display_item_0_7);
        ui->tableWidget->setItem(0,8,Display_item_0_8);
        ui->tableWidget->setItem(1,0,Display_item_1_0);
        ui->tableWidget->setItem(1,1,Display_item_1_1);
        ui->tableWidget->setItem(1,2,Display_item_1_2);
        ui->tableWidget->setItem(1,3,Display_item_1_3);
        ui->tableWidget->setItem(1,4,Display_item_1_4);
        ui->tableWidget->setItem(1,5,Display_item_1_5);
        ui->tableWidget->setItem(1,6,Display_item_1_6);
        ui->tableWidget->setItem(1,7,Display_item_1_7);
        ui->tableWidget->setItem(1,8,Display_item_1_8);
    

    .........
    .........
    ..........

    ui->tableWidget->setItem(513,0,FDP_Display_item_513_0);
    ui->tableWidget->setItem(513,1,FDP_Display_item_513_1);
    ui->tableWidget->setItem(513,2,FDP_Display_item_513_2);
    ui->tableWidget->setItem(513,3,FDP_Display_item_513_3);
    ui->tableWidget->setItem(513,4,FDP_Display_item_513_4);
    ui->tableWidget->setItem(513,5,FDP_Display_item_513_5);
    ui->tableWidget->setItem(513,6,FDP_Display_item_513_6);
    ui->tableWidget->setItem(513,7,FDP_Display_item_513_7);
    ui->tableWidget->setItem(513,8,FDP_Display_item_513_8);

    ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
    ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
    ui->tableWidget->setShowGrid(true);
    ui->tableWidget->horizontalHeader()->setSectionsMovable(true);
    ui->tableWidget->horizontalHeader()->setSectionsClickable(true);
    ui->tableWidget->horizontalHeader()->etSectionResizeMode(QHeaderView::Fixed);

    }

    Key_Up_Routine {

    int scroll;

    qDebug("current value = %d ", ui->tableWidget->verticalScrollBar()->value());
    scroll = ui->tableWidget->verticalScrollBar()->value();
    if(scroll >= 10) {
        ui->tableWidget->verticalScrollBar()->setValue((scroll - 10));
    }
    qDebug("new value = %d ", ui->tableWidget->verticalScrollBar()->value());
    

    }

    Key_Down_Routine {
    int scroll;

    qDebug("current value = %d ", ui->tableWidget->verticalScrollBar()->value());
    

    scroll = ui->tableWidget->verticalScrollBar()->value();
    ui->tableWidget->verticalScrollBar()->setValue((scroll + 10));
    qDebug("new value = %d ", ui->tableWidget->verticalScrollBar()->value());

    }


  • Lifetime Qt Champion

    @Sajeevan-K said in Vertical ScrollBar of QTableWidget not moving as expected:

    QTableWidgetItem * Display_item_0_0 = new QTableWidgetItem("0");
    QTableWidgetItem * Display_item_0_1 = new QTableWidgetItem("1");
    QTableWidgetItem * Display_item_0_2 = new QTableWidgetItem("2");
    QTableWidgetItem * Display_item_0_3 = new QTableWidgetItem("3");
    QTableWidgetItem * Display_item_0_4 = new QTableWidgetItem("4");
    QTableWidgetItem * Display_item_0_5 = new QTableWidgetItem("5");
    QTableWidgetItem * Display_item_0_6 = new QTableWidgetItem("6");
    QTableWidgetItem * Display_item_0_7 = new QTableWidgetItem("7");
    QTableWidgetItem * Display_item_0_8 = new QTableWidgetItem("8");
    QTableWidgetItem * Display_item_1_0 = new QTableWidgetItem("0");
    QTableWidgetItem * Display_item_1_1 = new QTableWidgetItem("1");
    QTableWidgetItem * Display_item_1_2 = new QTableWidgetItem("2");
    QTableWidgetItem * Display_item_1_3 = new QTableWidgetItem("3");
    QTableWidgetItem * Display_item_1_4 = new QTableWidgetItem("4");
    QTableWidgetItem * Display_item_1_5 = new QTableWidgetItem("5");
    QTableWidgetItem * Display_item_1_6 = new QTableWidgetItem("6");
    QTableWidgetItem * Display_item_1_7 = new QTableWidgetItem("7");
    QTableWidgetItem * Display_item_1_8 = new QtableWidgetItem("8");

    Why don't you use loops?



  • Hi jsulm,

    I tried using loop for this. But my knowledge in qt is limited.
    I don't know how to make the names like Display_item_0_0 in a loop.
    If it is a string it is easy. I think something like unstring operation is required for this.

    The code I sent, does not contain all the declarations of Display items and assigning it to QTableWidget. Otherwise it contains all the things that I am testing.

    Today by evening, I will make a Table with just 25 rows and see the result.
    Thank You for supporting.


  • Lifetime Qt Champion

    @Sajeevan-K said in Vertical ScrollBar of QTableWidget not moving as expected:

    I don't know how to make the names like Display_item_0_0 in a loop

    Do you really need names for all of them? What do you do with all these names later?



  • @Sajeevan-K said in Vertical ScrollBar of QTableWidget not moving as expected:

    I don't know how to make the names like Display_item_0_0 in a loop.

    http://www.cplusplus.com/doc/tutorial/arrays/



  • Hi jsulm,

    Thank You. I got Your point.

    And the code is rewritten as shown below:

    But the result is same. Still the maximum is 2 only.

    form_Table {

        ui->tableWidget->setGeometry(-2,40,804,15424);
        ui->tableWidget->horizontalHeader()->setDefaultSectionSize(80);
        ui->tableWidget->verticalHeader()->setDefaultSectionSize(30);
    
        ui->tableWidget->setRowCount(514);
        ui->tableWidget->setColumnCount(9);
    
    
        ui->tableWidget->setColumnWidth(0,80);
        ui->tableWidget->setColumnWidth(1,80);
        ui->tableWidget->setColumnWidth(2,80);
        ui->tableWidget->setColumnWidth(3,80);
        ui->tableWidget->setColumnWidth(4,80);
        ui->tableWidget->setColumnWidth(5,80);
        ui->tableWidget->setColumnWidth(6,80);
        ui->tableWidget->setColumnWidth(7,80);
        ui->tableWidget->setColumnWidth(8,80);
    
    
    
        QStringList horz_header;
        horz_header.clear();
        horz_header.append(“T1”);
        horz_header.append(“T2”);
        horz_header.append(“T3”);
        horz_header.append(“T4”);
        horz_header.append(“T5”);
        horz_header.append(“T6”);
        horz_header.append(“T7”);
        horz_header.append(“T8”);
        horz_header.append(“T9”);
        ui->tableWidget->setHorizontalHeaderLabels(horz_header);
    
        QStringList vert_header;
        vert_header.clear();
        vert_header.append("P1");
        vert_header.append("P2");
        vert_header.append("P3");
        vert_header.append("P4");
    
        ui->tableWidget->setVerticalHeaderLabels(vert_header);
        ui->tableWidget->horizontalHeader()->setVisible(true);
        ui->tableWidget->verticalHeader()->setVisible(true);
        ui->tableWidget-setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
        ui->tableWidget->setAutoScroll(false);
    

    QStringList str_list;
    str_list.clear();
    str_list.append("0");
    str_list.append("1");
    str_list.append("2");
    str_list.append("3");
    str_list.append("4");
    str_list.append("5");
    str_list.append("6");
    str_list.append("7");
    str_list.append("8");
    int row, column;
    for (row = 0; row < 514; row++) {
    for (column = 0; column < 9; column++) {
    QTableWidgetItem * Display_item = new QTableWidgetItem(str_list.at(column));
    ui->tableWidget_FDP->setItem(row,column, Display_item );
    }
    }

    ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
    ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
    ui->tableWidget->setShowGrid(true);
    ui->tableWidget->horizontalHeader()->setSectionsMovable(true);
    ui->tableWidget->horizontalHeader()->setSectionsClickable(true);
    ui->tableWidget->horizontalHeader()->etSectionResizeMode(QHeaderView::Fixed);

    }

    Key_Up_Routine {

    int scroll;

    qDebug("current value = %d ", ui->tableWidget->verticalScrollBar()->value());
    scroll = ui->tableWidget->verticalScrollBar()->value();
    if(scroll >= 10) {
        ui->tableWidget->verticalScrollBar()->setValue((scroll - 10));
    }
    qDebug("new value = %d ", ui->tableWidget->verticalScrollBar()->value());
    

    }

    Key_Down_Routine {
    int scroll;

    qDebug("current value = %d ", ui->tableWidget->verticalScrollBar()->value());
    

    scroll = ui->tableWidget->verticalScrollBar()->value();
    ui->tableWidget->verticalScrollBar()->setValue((scroll + 10));
    qDebug("new value = %d ", ui->tableWidget->verticalScrollBar()->value());

    }


  • Lifetime Qt Champion

    @Sajeevan-K You still can simplify your code with loops :-)



  • Hi jsulm,

    Thank You for Your suggestions. Today I am busy with my work. Tomorrow I will test it and give a feedback.



  • Hi jsulm,

    Sorry for the delay. I have been busy with a customer inspection.

    As per Your suggestion, I reduced it further as shown below.

    Now the maximum() is reduced to 1.

    form_Table {

    int row, column;

        ui->tableWidget->setGeometry(-2,40,804,15424);
    
        ui->tableWidget->horizontalHeader()->setDefaultSectionSize(80);
    
        ui->tableWidget->verticalHeader()->setDefaultSectionSize(30);
    
        ui->label_FDP_Display->setGeometry(-2,0,804,40);
    
    
        ui->tableWidget->setRowCount(514);
    
        ui->tableWidget->setColumnCount(9);
        for (column = 0; column < 9; column++) {
            ui->tableWidget->setColumnWidth(column,80);
        }
    

    QStringList horz_header;
    horz_header.clear();

        QString hh_str;
        for (column = 0; column < 9; column++) {
            hh_str.clear();
            hh_str.append("T");
            hh_str.append(QString::number(column));
            horz_header.append(hh_str);
        }
    

    ui->tableWidget->setHorizontalHeaderLabels(horz_header);

    QStringList vert_header;
        vert_header.clear();
    
        QString vh_str;
        for (row = 0; row < 514; row++) {
            vh_str.clear();
            vh_str.append("P");
            vh_str.append(QString::number(row));
            vert_header.append(vh_str);
        }
    

    ui->tableWidget->setVerticalHeaderLabels(vert_header);

    ui->tableWidget->horizontalHeader()->setVisible(true);
    ui->tableWidget->verticalHeader()->setVisible(true);
    ui->tableWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
    ui->tableWidget->setAutoScroll(false);

        QString item_str;
        for (row = 0; row < 514; row++) {
            for (column = 0; column < 9; column++) {
                item_str.clear();
                item_str.append(QString::number(row));
                item_str.append(",");
                item_str.append(QString::number(column));
                QTableWidgetItem * FDP_Display_item = new QTableWidgetItem(item_str);
                ui->tableWidget->setItem(row,column, FDP_Display_item );
            }
        }
    

    ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);

        ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
    

    ui->tableWidget->setShowGrid(true);
    ui->tableWidget->horizontalHeader()->setSectionsMovable(true);
    ui->tableWidget->horizontalHeader()->setSectionsClickable(true);
    ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);

    }

    Key_Up_Routine {

    int scroll;

    qDebug("current value = %d ", ui->tableWidget->verticalScrollBar()->value());
    scroll = ui->tableWidget->verticalScrollBar()->value();
    if(scroll >= 10) {
        ui->tableWidget->verticalScrollBar()->setValue((scroll - 10));
    }
    qDebug("new value = %d ", ui->tableWidget->verticalScrollBar()->value());
    

    }

    Key_Down_Routine {
    int scroll;

    qDebug("current value = %d ", ui->tableWidget->verticalScrollBar()->value());
    

    scroll = ui->tableWidget->verticalScrollBar()->value();
    ui->tableWidget->verticalScrollBar()->setValue((scroll + 10));
    qDebug("new value = %d ", ui->tableWidget->verticalScrollBar()->value());

    }



  • Hi jsulm,

    I could finally solve the issue. The problem was in the line

    ui->tableWidget->setGeometry(-2,40,804,15424);

    Generally for ui->tableWidget->setGeometry(x,y,width,hight),

    hight should be equal to number of rows in one page * default vertical section size.

    Thank You for the hints SGaist, jsulm


Log in to reply