Problem description :
Used in the project QTableWidget
form , Want to set the table header color to blue , The colors of the lines are displayed alternately . Google for a long time , Can't be set successfully . In fact, it turns out that , There are two main reasons for unsuccessful setup :
* firstly , The method provided in other people's blog was wrong ;
* second , Because there is no code prompt for setting the header color code , I typed the wrong code when I wrote it .
terms of settlement :
Direct code :
// Record six strings to the string list QStringList listStudents; // Add six strings to the string list listStudents <<
tr(" full name ") << tr(" Telephone ") << tr(" address ") << tr(" Age ") << tr(" Gender ") << tr(" class "); // Set horizontal meter
ui->tableWidgetStudents->setHorizontalHeaderLabels(listHeaders); // Set header color
ui->tableWidgetStudents->horizontalHeader()->setStyleSheet("QHeaderView::section{background:skyblue;}");
// Set the color alternate display of adjacent lines ui->tableWidgetStudents->setAlternatingRowColors(true); // Vertical indicator is not displayed
ui->tableWidgetStudents->verticalHeader()->setVisible(false);
* When setting the horizontal indicator , You can use one QStringList data structure . In this way, it is much more labor-saving to set the header than to use the cycle to set the single header directly .
* When writing the specific code of header color setting QT Creater No code prompt is provided , So be sure to spell and punctuate correctly .
Technology