Question

I have a QTableWidget with the following style sheets applied:

    QTableWidget
    {
    border:2px groove #96A8A8;
    border-radius:3px;
    selection-background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                             stop: 0 #D7F4F7, stop: 0.4 #CEECF0,
                             stop: 0.6 #C5E4E8, stop: 1.0 #D7F4F7);
    selection-color:black;
    }

    QTableWidget QHeaderView::section
    {
    border-bottom:0px groove #8BA6D9;
    border-left:0px groove #8BA6D9;
    border-right:2px groove #8BA6D9;
    border-top:0px;
    padding:5px;
    background:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                             stop: 0 #F8FCFE, stop: 0.4 #EBEEF2,
                             stop: 0.5 #E0E5EA, stop: 1.0 #DADEEA);


    color:black;
    outline:0px;
    }

    QTableWidget::item
    {
    padding:5px;
    outline:0px;
    }

This CSS code give me the looks I want. However, as soon as I start filling up the table with TableWidgetItems (more than 15items/rows), my table lost it's header decoration (that is, the header style is revert back to default window style) even though the rest of the table style sheet properties are still working.

What is causing the problem?

FYI, I applied the following properties to the table as well

mytable.setEditTriggers(QtGui.QTableWidget.NoEditTriggers)
mytable.setSelectionBehavior(QtGui.QTableWidget.SelectRows)
mytable.setSelectionMode(QtGui.QTableWidget.SingleSelection)
mytable.horizontalHeader().setStretchLastSection(True)
vheight = mytable.verticalHeader()
vheight.setDefaultSectionSize(50)

I am using Python 2.7.3 on Windows XP SP3

Was it helpful?

Solution

I don't know what is causing this behaviour. However, there is a work around to get the header decoration to stick. You can set the style sheet for the application via QApplication.setStyleSheet, instead of setting the style sheet for the widget.

This will set all QTableWidgets to the same style sheet, as a bonus, assuming you want this effect. If not, you could subclass and set style sheets according to the subclassed widgets.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top