[Tutor] pyqt4 set horizontal header item - extra info

Phil phil_lor at bigpond.com
Sun Mar 31 09:30:20 CEST 2013


On 31/03/13 14:29, Phil wrote:
> Thank you for reading this.
>
> I want to set a table widget header based on its cell contents.
>
> The following sets all of the headers;
>
> self.tableWidget.setHorizontalHeaderLabels(["One", "Two", "Etc"])
>
> However, self.setHorizontalHeaderItem ( 1, ["test"]) and
> self.setHorizontalHeaderItem ( 1, "test") fail with the following error;
>
> "'MainWindow' object has no attribute 'setHorizontalHeaderItem'"
>
> setHorizontalHeaderItem() exists in the documentation so I must be using
> it incorrectly. I've played with this for quite some time and searched
> the Internet for an answer. Can anyone offer a suggestion?
>

I now realise the correct syntax is;

self.tableWidget.setHorizontalHeaderItem (1, QTableWidgetItem *item)

I have done this many years ago in C++ but I don't quite see how to get 
a QTableWidgetItem in Python.

-- 
Regards,
Phil


More information about the Tutor mailing list