以前使用QTableWidget时,窗口固定大小,可以设置最后一览固定大小,但是如果窗口自适应,那最后一览常常出现问题,还好Qt有自己的解决方法,代码:
QTableWidget *logTableWidget = new QTableWidget;ui->logTableWidget->setColumnCount(3);QStringList header;header<<"time" << "tag" << "log";ui->logTableWidget->setHorizontalHeaderLabels(header);ui->logTableWidget->horizontalHeader()->setStretchLastSection(true);//关键ui->logTableWidget->setColumnWidth(0, 100);ui->logTableWidget->setColumnWidth(1, 100);ui->logTableWidget->setContextMenuPolicy(Qt::CustomContextMenu);ui->logTableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);