QTableWidget, center text and change color to a specific VerticalHeader

1

I'm making a table with QTableWidgetItem , the problem that occurs to me is in VertialHeader

I need the text to be centered and to define a different text color to some items; for example the item ( Gastos must be red).

Within the stylesheet try the following to modify the alignment of the text but it did not work:

QHeaderView::section:vertical{ qproperty-defaultAlignment: AlignHCenter; }

As for the text color of itemVerticalHeader , I could not solve anything.

I hope you can help me I leave a screenshot of the table:

    
asked by Revsky01 01.09.2018 в 07:15
source

1 answer

1

First, to specify the alignment of the text via the style sheet if you want both headers with the centered text you can do:

QHeaderView{qproperty-defaultAlignment: AlignHCenter}

Another option is to do it via code:

tableWidget.verticalHeader().setDefaultAlignment(QtCore.Qt.AlignHCenter)

Now, since you are using Qt Designer to create the structure of your table, you can individually specify whether you want both the alignment and the color of the header items by modifying their properties in the table's edit dialog:

  • Right click on the table and click on the Edit Items ... option on the menu:

  • You select the Rows tab, the item you want to modify and click on the Properties

    button

  • Look for property textAlignment and on the value assign AlignHCenter .

  • With this we center that item. Now, for the color of the text look for the property foreground and in Style assign solid as value.

  • Finally go to Color just below and select the color you want.

  • With this you can get what you want:

        
    answered by 01.09.2018 / 12:12
    source