[Qt-interest] QTable: How to retrieve contents from each cells

Andreas Diehl Andreas_Diehl at abs.org
Mon Jan 5 14:00:07 CET 2009


Hello Miss Rain,
 
the you methods you need are:
    void QTable::setCellWidget(int row, int column, QWidget widget)

    QWidget QTable::cellWidget(int row, int column)

With those you can insert QComboBoxes and other widgets into your table.
In order to read values you'll need to cast the cellWidget() return like
(QtJambi example):

 

String getValue(int row, int col)

{

    QWidget wdg = myTable.cellWidget(row, col);

    if (wdg == null)

        return "";

    if (wdg instanceof QComboBox)

        return ((QComboBox)wdg).currentText();

    if (wdg instanceof QSpinBox)

        return ""+((QSpindBox)wdg).value();

    //and so on

    return "";

}

 
A method like setValue(int, int, String) would look similar. But you
must take care of connecting signals: itemDoubleClicked for example has
no effect because it treats QTableWidgetItems. By setting a cell widget
events (like double clicks) are passed to the widget instead to the
table. Thus, if you want to do some input handling you have to use the
signals of the widget itself (QComboBox example):
 
       ...
    QComboBox myBox = new QComboBox();
    myBox.currentIndexChanged.connect(this,
"slotComboBoxContentsChanged()");
    myTable.setCellWidget(row, col, myBox);
    ...
 
Hope it helps.
Regards,
    Andreas
 

 

________________________________

	Von: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] Im Auftrag von rain
hanatawa119
	Gesendet: Montag, 5. Januar 2009 13:04
	An: Qt interest trolltech
	Betreff: [Qt-interest] QTable: How to retrieve contents from
each cells
	
	
	Hey guys,
	
	I'm currently developing a program such that users can insert
values onto the cells (using QTable library) and i actually want to
retrieve each values/contents from the cells and save the data onto text
files. My doubt is i can easliy retrieve values if the contents are text
but what if i have Comboboxes and pixmap as widgets inside the cell. How
to read the values and change it as text/string like? I really need help
by now... Thanx.
	
	Regards,
	
	-Miss Rain-
	
	
________________________________

	check out the rest of the Windows Live(tm). More than
mail-Windows Live(tm) goes way beyond your inbox. More than messages
<http://www.microsoft.com/windows/windowslive/>
--
Mit freundlichen Gru?en
Andreas Diehl 
 
-------------------------- ABS -------------------------
ABS Systemberatung OHG          Tel: +49 (0)7053/9290-
Hauffstr. 9                     Fax: +49 (0)7053/9290-
D-75385 Bad Teinach-Zavelstein        http://www.abs.org
Registergericht Calw HRA 1031
[mailto:Andreas_Diehl at abs.org]
 
----- Loesungen fuer den Maschinen- und Anlagenbau -----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090105/349e5769/attachment.html 


More information about the Qt-interest-old mailing list