Registered Member
|
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:
but I get this error:
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:
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. |
KDE Developer
|
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. |
Registered Member
|
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 |
KDE Developer
|
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) |
Registered Member
|
Hi David, that did the trick, thanks !!
|
KDE Developer
|
No problem.
Make sure you post on kde-look.org when you finish! |
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]