c++ – How to set column span for QTableWidget?


I’d like to create a table like this:

what I want

But as for now I’ve only managed this:

what I got

How to setup the span in the second row to get this two spanned columns to have the same width as in the first image?

Here is the code of my table implementation:

MovableQtableWidget::MovableQtableWidget(const QString& text, QWidget* parent)
    : QTableWidget(2,3) {
    setWindowTitle(text);

    QStringList ColHeaders, RowHeaders;
    ColHeaders << "Name" << "DR" << "DT";
    RowHeaders << "Armor" << "Ammo";

    this->setHorizontalHeaderLabels(ColHeaders);
    this->setVerticalHeaderLabels(RowHeaders);
    this->setSpan(1, 1, 2, 2);

    this->setStyleSheet("\
        QTableWidget { background-color: rgba(0, 255, 255, 255) }\
        QHeaderView { background-color: rgba(0, 0, 255, 100) }\
        QHeaderView::section { background-color: rgba(0, 255, 0, 100) }\
        QTableCornerButton::section { background-color: rgba(255, 0, 0, 100) }\
        QTableView{border : 3px solid red}\
    ");
}



Source link

Leave a Comment