This forum has been archived. All content is frozen. Please use KDE Discuss instead.

How to use QTableWidget on a python plasmoid

Tags: None
(comma "," separated)
mazter
Registered Member
Posts
28
Karma
0
OS
Hi,

I'm starting to learn python and for this I'm trying to use a QTableWidget on a plasmoid, but I'm not being able to use the PyQt API as it is documented here:

http://www.riverbankcomputing.co.uk/sta ... idget.html

That's the only python bindings documentation I could find and AFAIK, that is the official one. According to that documentation, QTableWidget has a constructor the receives the number of columns and rows. I'm using it like this:

Code: Select all
table = QTableWidget.__init__(self,2,2)


but I get this error:

Code: Select all
/contents/code/main.py", line 52, in init
    table = QTableWidget.__init__(self,2,2)
TypeError: QObject(QObject parent=None): argument 1 has unexpected type 'int'


it only works without the numeric parameters. So looking at the documentation I see there's another way to set the number of colums using the setColumnCount and setRowCount, but with any of them I get the following error:

Code: Select all
AttributeError: 'NoneType' object has no attribute 'setColumnCount'


So I don't know what I'm doing wrong, it seems I have a different version of PyQt than the one in the referred documentationm and those methods do not exist or are different. I'm using KDE 4.4 and python-qt4 4.7 on Mandriva 2010 if it is worth mentioning. Can anyone give me a hint of how to use QTableWidget or better yet, has a working example inside of a plasmoid ?

Thanks.
User avatar
david_edmundson
KDE Developer
Posts
359
Karma
1
OS
table = QTableWidget.__init__(self,2,2)

Few things:
1) Generally it's wrong to explicitly call an init method. It is called when you create the object

2)You don't need to pass 'self' as the first argument to the method. This is handled by Python, all instance methods start with the word 'self', but it doesn't need passing. This is causing the offset in args and error you are seeing.

table = QTableWidget(2,2)

(you probably actually want)
table = QTableWidget(2,2,self)

where self is now filling 'parent' argument in QTableWidget.__init__ (self, int, int, QWidget parent = None)

Note: You're going to hit a 'problem' (not an unsolvable major one) when you try adding a qtablewidget to a plasmoid. Plasmoids display QGraphicsWidget items. QTableWidget is a QWidget. Be on the look out for that when you have problems adding it to the layout.
mazter
Registered Member
Posts
28
Karma
0
OS
Hi David, thank you for your answer, I will try it tonight.

About the problem you mention I will face, which other alternatives I can use? which other widget can I use that inherits from QGraphicsWidget that gives something like a table?

Thanks
User avatar
david_edmundson
KDE Developer
Posts
359
Karma
1
OS
You /may/ (I don't know for sure) need to run

tableWidget = QTableWidget(2,2)
tableGraphicsWidget = self.scene().addWidget(tableWidget)
# this creates a QGraphicsProxyWidget (a QWidget in a QGraphicsWidget)
# I'm assuming self is of type Plasma.Applet


someGraphicsLayout.addWidget(tableGraphicsWidget)
mazter
Registered Member
Posts
28
Karma
0
OS
Hi David, that did the trick, thanks !!
User avatar
david_edmundson
KDE Developer
Posts
359
Karma
1
OS
No problem.

Make sure you post on kde-look.org when you finish!


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]