[PyQt] Problems with hideColumn() in QTableView

Sebastian Vetter svetter at s-vetter.org
Fri Feb 8 16:32:02 GMT 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hey everyone,

I've got a little problem with QTabelView when I try to hide columns or
rows. When I set the model and load some data all columns and rows are
displayed in the table view widget. I would like to display only for
(specific) columns of ca. 33 but it doesn't seem to work. A code excerpt
follows. Can anyone help me with this? What am I doing wrong?
Thanks a lot for your help. I appreciate it.

cheers,
Seb


#Qt modules
from PyQt4.QtGui import  QTableView, \
			 QWidget,\
			 QGridLayout,\
			 QTableWidgetItem

from PyQt4.QtCore import QString

#project modules
from src.gui.RbSectorItem import RbSectorItem
from src.gui.RbCategoryItem import RbCategoryItem
from src.gui.RbCategoryView import RbCategoryView
from src.RbSpreadSheet import FileType

class RbCategoryEditor(QWidget) :
~    """ Widget to display XLS or CSV files in a tabular view. """

~    def __init__(self, model, parent=None) :
	""" Initialise tabular widget. """
	#Initialise base class first
	QWidget.__init__(self, parent)
	####
	# Set member variables
	self.__spreadsheet_view = QTableView()
	self.__spreadsheet_view.setModel(model)
	# Delegate Items
	self.__sector_delegate = RbSectorItem()
	self.__category_delegate = RbCategoryItem()
	####
	# Setupt grid layout for widget
	grid_layout = QGridLayout( self )
	grid_layout.addWidget(self.__spreadsheet_view, 0, 0, 1, 1)

~    def setupTable(self, spreadsheet):
	""" Hides all columns that are not listed as visible columns."""
	header = spreadsheet.header()
	#Get column index for 'sector' and 'category'
	if 'sector' in header :
	    sector_index = header.index('sector')
	    self.__spreadsheet_view.setItemDelegateForColumn(
			sector_index, self.__sector_delegate)
	if 'category' in header :
	    category_index = header.index('category')
	    self.__spreadsheet_view.setItemDelegateForColumn(
			category_index, self.__category_delegate)

	####
	# Hiding column(s)
	self.__spreadsheet_view.hideColumn(0)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHrIQC/ZEwc0fz/xMRAtfRAJ44CkBPjMKZkPlORRnV/wUbpQmzjQCfamDw
1WuUxa1cWzqkkTRybWtxCmQ=
=wtj3
-----END PGP SIGNATURE-----


More information about the PyQt mailing list