I have a QTableWidget with 2 columns, with a QHeaderView.
I left align all QTableWidgetItems in the left column, center align the right column QTableWidgetItems.
How do I now do this aligning of text to my QHeaderView? Currently both columns are center aligned, I want the first column header to be left aligned, the right column header to be center aligned.
This is my code for adding the QHeaderView in my class:
setRowCount(0);
setColumnCount(2);
setColumnWidth(0, 400); //set width of 1st column, 2nd column will auto-fit to remaining space
header
->setSectionResizeMode
(1,
QHeaderView::Stretch);
//let last column stretch to fit the table headerLabels << "Start of Stoppage" << "Duration";
setHorizontalHeaderLabels(headerLabels);
horizontalHeader()->setFont(*font);
setRowCount(0);
setColumnCount(2);
setColumnWidth(0, 400); //set width of 1st column, 2nd column will auto-fit to remaining space
QHeaderView *header = this->horizontalHeader();
header->setSectionResizeMode(1, QHeaderView::Stretch); //let last column stretch to fit the table
QStringList headerLabels;
headerLabels << "Start of Stoppage" << "Duration";
setHorizontalHeaderLabels(headerLabels);
QFont *font = new QFont("Helvetica",20);
horizontalHeader()->setFont(*font);
To copy to clipboard, switch view to plain text mode
Thank you, I appreciate any help on this.
Bookmarks