Search code examples
c++cssqtqtstylesheets

border and text qss settings at QTableView


Here's I am trying to do that: enter image description here

but I set that stylesheet in my QTableView:

QTableView {
    gridline-color: black;
    background-color: transparent;
    }
QHeaderView {background-color: transparent;

}
QHeaderView::section{
border-style: none;
border-bottom: 1px solid rgb(0,0,0);
background-color: transparent;
margin-bottom:5px;
margin-top:5px;
}
QTableView QTableCornerButton::section {
     bottom-style:none;
     border-bottom: 1px solid rgb(0,0,0);

 }

Result is this:enter image description here

I can handle with size problem for future but there is two main problem over here:

1.Column text between border there isnt any space, I did margin-top:5px; and margin-bottom:5px; but it changed for all QHeaderView not only QHeaderView's Text. (Solution is use padding instead of margin)

2.Every row has a right ,left even top border. I dont want that.

I tried this:

QTableView QTableCornerButton::section {
     border-style:none;
     border-bottom: 1px solid rgb(0,0,0);

 }

Unfortunately there is a problem at QTableCornerButton:section it doesn't work...

Thank you for any helping


Solution

  • Note : I haven't verified, these are just suggestions to try, please upload the output if needed

    1 - What do you mean by "it changed for all QHeaderView not only QHeaderView's Text"?

    Maybe you expected to set margin only to the headerview's content (text) : in that case use the padding not margin.

    QHeaderView::section{
    /* your style */
    padding-bottom:5px;
    padding-top:5px;
    }
    

    2 - Every row has a right ,left even top border. I dont want that.

    QTableView {
        /* sone additional style */
        gridline-color: cyan
        background-color: cyan
    }
    
    QTableView::item
    {
        border-style: none;
        border-bottom: 1px solid rgb(0,0,0);
    }
    

    I would try to use the border-style (set to none) as you did in QHeaderView's style.

    Edit : You certainly must disable the showgrid's option of your QTableView by code to make it a working solution

    tableView.setShowGrid(false);