c++qtqt5qtablewidgetqheaderview

Add custom widgets as QTableWidget HorizontalHeader


Is it possible to display a custom QWidget on the QHeaderView instead of just the generic string?

Also, is it possible to change the height of the horizontalHeaderItem only? It crashes when I do this:

(ui->myTable->horizontalHeaderItem(0))->setSizeHint(QSize(200,300));

Solution

  • I solved it by adding headers programmatically in my .cpp file rather than on the design file.

    QTableWidgetItem *header1 = new QTableWidgetItem("Title of Header 1");
    header1->setBackgroundColor(QColor(81,81,81));
    header1->setIcon(QIcon(QPixmap(":/images/header1Icon.png")));    
    header1->setSizeHint(QSize(450,35));
    ui->myTable->setHorizontalHeaderItem(0, header1);