PDA

View Full Version : Column/Row no of ComboBox Widget in Table



ankurjain
19th May 2006, 06:20
hi guys,
i've done filtering in my table.
i've set a combo Widget in a table in first row.each combo in each column all the text of the cells below it. then whatever text i select the following rows will be shown or hidden.

i used :


QTableWidget *table = new QTableWidget;
table->setCellWidget(row,col,comboWidget);
connect(comboWidget, SIGNAL(activated(const QString &)),table,SLOT(change(const QString &)));


Now i want the row no or column no of which the combo is selected.
column no for matching the item selected from the combo to match in the column,
row no to hide/show the row.

how can i implement it ?

munna
19th May 2006, 06:57
QTableWidget::currentColumn() can give you which combo is selected.

Use QComboBox's activated signal to find out about the row.

ankurjain
19th May 2006, 09:23
the activated signal gives the index of the item in the list of combobox. so we can't use it here.

for the currentColumn stuff ... u r very right this must happen. but what is happening here is that, if i select some other cell of the table and then do the combo operation the focus from that cell is not shifting to combobox. so the currentColumn gives the col no of selected cell.

this is the problem i m facing ....

zlatko
19th May 2006, 09:31
Yes sure but why dont want use currentColumn() or currentRow() method ?

zlatko
19th May 2006, 09:33
so the currentColumn gives the col no of selected cell.


use currentRow then :)

ankurjain
19th May 2006, 09:49
hi all,

hav a look at my code


void QGrid::autoFilter()
{
int columnCount = this->columnCount();
int rowCount = this->rowCount();
QStringList filter;
QString temp_string;
QComboBox *newCombo;
for(int c = 0;c<columnCount;c++)
{
for(int r = 1; r<rowCount;r++)
{
temp_string = this->item(r,c)->text();
if(!filter.contains(temp_string))
filter << temp_string;
}
filter << "None";
newCombo = new QComboBox(this);
newCombo->addItems(filter);
newCombo->setCurrentIndex(filter.count()-1);
this->setCellWidget(0,c,newCombo);
filter.clear();
connect(newCombo,SIGNAL(activated(const QString &)),this,SLOT(testAnother(const QString &)));
}
}

this i did to get the combo in first row with all the unique values in the columns below each of them.

now look at the image below :

http://img19.imageshack.us/img19/1006/mytable7oj.th.jpg (http://img19.imageshack.us/my.php?image=mytable7oj.jpg)

what i did, selected the lower cell first, then selected the combo, then also the focus from the lower cell isn't going. here two cells are selected simultaneously.

if i try to get the cell contents for the first row(having combo) using this->item(0,0), it ain't giving the text of the combo...

pls suggest something ...

jpn
19th May 2006, 09:52
If the combo box is placed as a cell widget, the current column and current row is not updated "correctly" when interacting with the combo. This is because the combo box is over the cell and therefore the cell doesn't get selected.

- store combos as member variables, maybe event map them somehow to their cells (QMap<QPoint, QComboBox*> for instance)
- subclass qcombobox and add properties for row and column
- use qobject's objectname property to store a qpoint

jpn
19th May 2006, 09:58
// set column index for combo boxes
newCombo->setObjectName(QString::number(c));

// the slot
void testAnother(const QString& text)
{
// retrieve column index of the sender of the signal
int c = sender()->objectName().toInt();
}

ankurjain
19th May 2006, 11:20
jpn:

thanx buddy.... i worked the 3rd solution.

thanx to munna, zlatko and all others who read the post and replied ....

this forum is really helpful to me ....

sumsin
22nd May 2006, 09:22
I also want to do the same thing and I have approached to implement this thing is, I subclass the QComboBox and add some my custom slot and signal.
header file


#ifndef _MY_COMBO_BOX_H
#define _MY_COMBO_BOX_H

#include <qobject.h>
#include <qcombobox.h>

//***********Defination of OdyComboBox****************

class CMyComboBox : public QComboBox
{
Q_OBJECT

public:
CMyComboBox ( int row, int column, QWidget * parent, const char * name = 0 ) ;

signals:
void activated (int row, int column, const QString & string);

public slots:
void reEmitActivated(const QString &);

private:
int row;
int column;
};

#endif


and source File



//***********Implementation of OdyComboBox****************

CMyComboBox::CMyComboBox (int row, int column, QWidget * parent, const char * name )
: QComboBox( parent, name ), row(row), column(column) {

setPaletteBackgroundColor( Qt::white );
connect( this, SIGNAL(activated (const QString &)), this, SLOT(reEmitActivated(const QString &) ));
}

void CMyComboBox::reEmitActivated(const QString & string) {
emit activated( row, column, string );
}

ankurjain
22nd May 2006, 10:03
hi sumsin,
ur implementation was nice .... i got a bit confused in the code :



CMyComboBox::CMyComboBox (int row, int column, QWidget * parent, const char * name )
: QComboBox( parent, name ), row(row), column(column)


u inherited QComboBox, now in the constructor, what the lines row(row),column(column) mean?



void CMyComboBox::reEmitActivated(const QString & string) {
emit activated( row, column, string );
}


here how u got the row and column ?

i am a new user to this ..... so if its too easy, then also pls reply ....

munna
22nd May 2006, 10:26
u inherited QComboBox, now in the constructor, what the lines row(row),column(column) mean?

This is NOT inside QComboBox's constructor. Row and Column are getting initialized.


here how u got the row and column ?

row and column are member variables of CMyComboBox.

sumsin
23rd May 2006, 05:21
Exactly. What munna says.
Thanks munna. :)

lekhrajdeshmukh
6th December 2011, 11:03
Dear Ankur,
Could you please provide the complete code .I am beginner and not able to do anything after implementation of combo box.
Thanks in advance.

Added after 1 39 minutes:

Dear Jpn,
could you please help me how to implement " qobject's objectname property to store a qpoint" feature.I have implemented on same way as ankur has mentioned and now i am getting combo box on my table but not getting any idea to implement slot named testAnother. As i m beginner and i don't have any more idea about this.So request you to please help me out from this problem.
Thanks in advance