Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QTableView/QTableWidget grid stylesheet - grid line width

Tags:

c++

css

qt

qt4

I would like to display table in Qt with 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 2px grid width or no grid at all.

I Have folowing window with one QTableWIdget

QTableWidget

and asociated 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 4.8.5 and I can't upgrade to version 5.x.

like image 734
j123b567 Avatar asked Oct 02 '14 13:10

j123b567


2 Answers

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;
}
like image 167
j123b567 Avatar answered Nov 18 '22 01:11

j123b567


I think what you did is you added additional border for section cells, and the section properties should look like that ( although I did not try this solution )

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

For more information how to style your headers, see:

http://pastebin.com/svReqHr3

HowTo draw correct CSS border in header?

like image 21
pmpod Avatar answered Nov 18 '22 02:11

pmpod