How to resize vertical header in QTableWidget



  • I cannot figure out how to set the vertical header size for a QTableWidget. I have tried using resizeSection, but that doesn't seem to do anything other than wiping out the text I put in the vertical header. I have done a search here to no avail. Does anyone have an example of how to do this?

    Thanks.



  • Is that what you want ?

    tableView->verticalHeader()->setDefaultSectionSize(YourValue)


  • I believe I have tried that to no avail, but I'll try it again and report back. Thanks.
    No, that seems to have no effect, but I don't know what "tableView" signifies exactly.
    Here's my code:

    QTableWidget *InsurancePremiumTable;
    ...
    ui->InsurancePremiumTable->setColumnCount(MaxYearsToModel);
    m_InsurancePremiumRowNames.append("Ins. Premium");
    ui->InsurancePremiumTable->setVerticalHeaderLabels(m_InsurancePremiumRowNames);
    ui->InsurancePremiumTable->verticalHeader()->setDefaultSectionSize(500);
    for (int row = 0; row < ui->InsurancePremiumTable->rowCount(); ++row)
    for (int column = 0; column < ui->InsurancePremiumTable->columnCount(); ++column)
    {
    QTableWidgetItem *newItem = new QTableWidgetItem("");
    ui->InsurancePremiumTable->setItem(row, column, newItem);
    }

    Can you see what I'm doing wrong? 500 isn't the actual size that I want, just a size that should show me that it's doing something.



  • try ui->InsurancePremiumTable->verticalHeader()- setSizeHint( QSize (500,500 ) );



  • No, that doesn't compile.
    1>mainwindow.cpp(737): error C3861: 'setSizeHint': identifier not found



  • This post is deleted!


  • Try this:

    ui->InsurancePremiumTable->verticalHeader->setResizeMode(QHeaderView::Fixed);
    ui->InsurancePremiumTable->verticalHeader->setDefaultSectionSize( 500 );
    

    Or:

    ui->InsurancePremiumTable->verticalHeader->setResizeMode(QHeaderView::Fixed);
    ui->InsurancePremiumTable->verticalHeader()->resize( 500, 500 );
    

    If it doesn't help try changing size for a single row:

    ui->InsurancePremiumTable->setRowHeight( rowNumber, rowHeight );


  • This doesn't compile:
    ui->InsurancePremiumTable->verticalHeader()->setResizeMode(QHeaderView::Fixed);

    I get this error:
    mainwindow.cpp(736): error C2039: 'setResizeMode' : is not a member of 'QHeaderView'

    and if I write it as you did,
    ui->InsurancePremiumTable->verticalHeader->setResizeMode(QHeaderView::Fixed);

    then I get a different error:
    1>mainwindow.cpp(736): error C2227: left of '->setResizeMode' must point to class/struct/union/generic type


  • Lifetime Qt Champion

    Hi,

    You are missing a #include <QHeaderView> in mainwindow.cpp file



  • Nope, that doesn't help; I get the same error:
    1>mainwindow.cpp(745): error C2039: 'setResizeMode' : is not a member of 'QHeaderView'

    Any other suggestions?


  • Lifetime Qt Champion

    Because it's an obsolete function, see here for the replacement



  • That compiles okay but doesn't do anything visible other than wiping out my label

    Here's my code:

    ui->InsurancePremiumTable->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
    ui->InsurancePremiumTable->verticalHeader()->resizeSection(0, 500);
    m_InsurancePremiumRowNames.append("Ins.    Premium");
    ui->InsurancePremiumTable->setVerticalHeaderLabels(m_InsurancePremiumRowNames);
    for (int row = 0; row < ui->InsurancePremiumTable->rowCount(); ++row)
    	for (int column = 0; column < ui->InsurancePremiumTable->columnCount(); ++column)
    	{
    		QTableWidgetItem *newItem = new QTableWidgetItem("");
    		ui->InsurancePremiumTable->setItem(row, column, newItem);
    	}

  • Lifetime Qt Champion

    Your header width gets pretty big, isn't 500pixel a bit wide ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.