Search code examples
c++qtqtablewidgetqtstylesheetsqheaderview

QTableView/QTableWidget grid stylesheet - grid line width


I would like to display a table in Qt with a specific style. I want to draw all grid lines with same color and same width.

Problem is, that it is hard to style QHeaderView. All the time, I get a 2px grid width or no grid at all.

I have the following window with one QTableWidget:

QTableWidget

and associated stylesheet:

QWidget {
    background-color: #333333;
    color: #fffff8;
}

QHeaderView::section {
    background-color: #646464;
    padding: 4px;
    border: 1px solid #fffff8;
    font-size: 14pt;
}

QTableWidget {
    gridline-color: #fffff8;
    font-size: 12pt;
}

QTableWidget QTableCornerButton::section {
    background-color: #646464;
    border: 1px solid #fffff8;
}

Are there any tricks to have all grid lines 1px width? I'm using Qt 4.8.5, and I can't upgrade to versions 5.x.


Solution

  • The trick is border-style: none; in QHeaderView::section after witch border-left, border-right, border-top and border-bottom starts working. Correct style for QHeaderView::section should be:

    QHeaderView::section {
        background-color: #646464;
        padding: 4px;
        font-size: 14pt;
        border-style: none;
        border-bottom: 1px solid #fffff8;
        border-right: 1px solid #fffff8;
    }
    
    QHeaderView::section:horizontal
    {
        border-top: 1px solid #fffff8;
    }
    
    QHeaderView::section:vertical
    {
        border-left: 1px solid #fffff8;
    }