Qt so that each element in the middle (of the use of some qtablewidget) tableWidget content

First look at the effect of:

 

   // set the table style

    ui->tableWidget->verticalHeader()->hide();
    ui-> tableWidget-> horizontalHeader () -> setDefaultAlignment (Qt :: AlignHCenter); // header font center
    ui-> tableWidget-> setEditTriggers (QAbstractItemView :: NoEditTriggers); // cell is not editable
    ui-> tableWidget-> horizontalHeader () -> setStyleSheet ( "QHeaderView :: section {background: rgb (2,20,130); color: white;}"); // set the font color of the header
    ui-> tableWidget-> verticalHeader () -> setDefaultSectionSize (40); // set the row height
    ui-> tableWidget-> horizontalHeader () -> setStretchLastSection (true); // for each column sharing
    ui-> tableWidget-> horizontalHeader () -> setSectionResizeMode (QHeaderView :: Stretch); // column Scalable
    ui-> tableWidget-> setSelectionBehavior (QAbstractItemView :: SelectRows); // set the whole row is selected
     // so that each element tableWidget content centered
    for (int i=0;i<5;i++)
       {
           for (int j=0;j<8;j++)
           {
               ui->tableWidget->item(i,j)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
           }
       } 

One thing to note is that there are several odd row of data in the table, give i, j value assigned number, otherwise it will error "abnormal program end"

Guess you like

Origin www.cnblogs.com/wang--wei/p/11928234.html