set horizontal header item

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

set horizontal header item

Phil-2
Thank you for reading this.

I'm new to both Pyqt and this list. I want to set a table widget header
based on its cell contents. The documentation shows how it's done;

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

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

--
Regards,
Phil
_______________________________________________
PyQt mailing list    [hidden email]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: set horizontal header item

Phil-2
On 01/04/13 01:51, David Cortesi wrote:
> Like instantiating any class in Python: call the class name as a
> function, passing initialization values..
>
> self.setHorizontalHeaderItem( col_num, QTableWidgetItem( "Yabba Dabba") )
>

Thanks David, it all looks pretty straight forward except for the error
message;

"global name 'QTableWidgetItem' is not defined"

If this was C++ I'd be looking for an include file. Is there something
similar that I should be including, another module perhaps?

--
Regards,
Phil
_______________________________________________
PyQt mailing list    [hidden email]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: set horizontal header item

Phil-2
In reply to this post by Phil-2
On 01/04/13 08:00, Ryan Hanson wrote:
>
<cut>

>
> Oh okay I see. Did you try QtGui.QTableWidgetItem?

Thanks for your quick response Ryan. I hadn't tried QtGui, and this is
the error message;

"global name 'QtGui' is not defined"

The Eric IDE's main window starts like this;

from PyQt4.QtGui import QMainWindow

So I also tried PyQt4.QtGui, with the same result.

--
Regards,
Phil
_______________________________________________
PyQt mailing list    [hidden email]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: set horizontal header item

Phil-2
On 01/04/13 09:54, Ryan Hanson wrote:
> Try 'from PyQt4 import QtGui' then you can use everything under QtGiu.
> Like QtGui.QTreeWidgetItem

Thanks Ryan, that's the answer.

--
Regards,
Phil
_______________________________________________
PyQt mailing list    [hidden email]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Model copying

Jorge Tornero - Listas
In reply to this post by Phil-2
Thank you for reading this:

I' ve populated a tablewidget and I want to reuse its (internal) model
to pouplate a qcombobox . So far, I've done:

1) I create a qtableview and a model for it as newModel=tableWidget.model()
2) I set the model of my combo the same as the qtableview
3) I set combobox's view as the qtableview.

Of course it works... but when I remove a item in the "original"
tablewidget, it gets removed from the combo. I think it's amatter of
assignmente, etc... but I've tried with copy() and deepcopy() and it
throws an error:

TypeError: PyQt4.QtCore.QAbstractTableModel represents a C++ abstract
class and cannot be instantiated

Any idea on how to proceed?

Best regards,

Jorge Tornero
_______________________________________________
PyQt mailing list    [hidden email]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: Model copying

Andreas Pakulat
Hi,

On Fri, Dec 13, 2013 at 2:01 PM, Jorge Tornero - Listas <[hidden email]> wrote:
Thank you for reading this:

I' ve populated a tablewidget and I want to reuse its (internal) model to pouplate a qcombobox . So far, I've done:

1) I create a qtableview and a model for it as newModel=tableWidget.model()
2) I set the model of my combo the same as the qtableview
3) I set combobox's view as the qtableview.

Of course it works... but when I remove a item in the "original" tablewidget, it gets removed from the combo. I think it's amatter of assignmente, etc... but I've tried with copy() and deepcopy() and it throws an error:

TypeError: PyQt4.QtCore.QAbstractTableModel represents a C++ abstract class and cannot be instantiated

Any idea on how to proceed?

Sharing a model only makes sense if you want to make sure that all views using it show the same data. That also means that all views will drop items if they are removed from the model, this is intentional and not a bug.

Now if you don't want that, you actually don't want to share the model. So what you need to do is create a copy of the data that the model uses and then populate the combobox model with that. Since you use QTableWidget the underlying data is whatever you used to populate the QTableWidgetItems. That data is what you need to put into the combobox, you can't just use the model of the tablewidget.

Andreas
 

_______________________________________________
PyQt mailing list    [hidden email]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt