Column/Row no of ComboBox Widget in Table
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 :
Code:
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 ?
Re: Column/Row no of ComboBox Widget in Table
QTableWidget::currentColumn() can give you which combo is selected.
Use QComboBox's activated signal to find out about the row.
Re: Column/Row no of ComboBox Widget in Table
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 ....
Re: Column/Row no of ComboBox Widget in Table
Yes sure but why dont want use currentColumn() or currentRow() method ?
Re: Column/Row no of ComboBox Widget in Table
Quote:
Originally Posted by ankurjain
so the currentColumn gives the col no of selected cell.
use currentRow then :)
Re: Column/Row no of ComboBox Widget in Table
hi all,
hav a look at my code
Code:
void QGrid::autoFilter()
{
int columnCount = this->columnCount();
int rowCount = this->rowCount();
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->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
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 ...
Re: Column/Row no of ComboBox Widget in Table
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
Re: Column/Row no of ComboBox Widget in Table
Code:
// 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();
}
Re: Column/Row no of ComboBox Widget in Table
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 ....
Re: Column/Row no of ComboBox Widget in Table
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
Code:
#ifndef _MY_COMBO_BOX_H
#define _MY_COMBO_BOX_H
#include <qobject.h>
#include <qcombobox.h>
//***********Defination of OdyComboBox****************
{
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
Code:
//***********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 );
}
Re: Column/Row no of ComboBox Widget in Table
hi sumsin,
ur implementation was nice .... i got a bit confused in the code :
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?
Code:
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 ....
Re: Column/Row no of ComboBox Widget in Table
Quote:
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.
Quote:
here how u got the row and column ?
row and column are member variables of CMyComboBox.
Re: Column/Row no of ComboBox Widget in Table
Exactly. What munna says.
Thanks munna. :)
Re: Column/Row no of ComboBox Widget in Table
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