Search code examples
qtwindows-10qtablewidgetqheaderview

QHeaderView has no horizontal lines in Windows 10


enter image description here

QTableWidget headers have no horizontal lines in Windows 10. How can I fix it?


Solution

  • I had the same problem. It can be solved with the following style sheet on the table view/widget:

    if(QSysInfo::windowsVersion()==QSysInfo::WV_WINDOWS10){
        setStyleSheet(
            "QHeaderView::section{"
                "border-top:0px solid #D8D8D8;"
                "border-left:0px solid #D8D8D8;"
                "border-right:1px solid #D8D8D8;"
                "border-bottom: 1px solid #D8D8D8;"
                "background-color:white;"
                "padding:4px;"
            "}"
            "QTableCornerButton::section{"
                "border-top:0px solid #D8D8D8;"
                "border-left:0px solid #D8D8D8;"
                "border-right:1px solid #D8D8D8;"
                "border-bottom: 1px solid #D8D8D8;"
                "background-color:white;"
            "}");}
    

    This is C++ code but it should be easy to adapt to your needs.

    Note1: The background-color and padding are unfortunate but they are necessary to make our custom rendering looks like the default one.

    Note2: The color of the border is the color of the grid on my system. I did not use the color of the default header.

    Note3: The QTableCornerButton::section part is necessary to add the missing border below the top left corner. If the vertical header is not visible, the missing line is invisible too.

    Note4: If (like me) you find that the ugly grey rectangle below the name of your rows needs fixing, just add QHeaderView{background-color:white;} to your style sheet.

    Hope this helps.