Results 1 to 14 of 14

Thread: Column/Row no of ComboBox Widget in Table

  1. #1
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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 :
    Qt Code:
    1. table->setCellWidget(row,col,comboWidget);
    2. connect(comboWidget, SIGNAL(activated(const QString &)),table,SLOT(change(const QString &)));
    To copy to clipboard, switch view to plain text mode 

    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 ?
    Do what u r afraid to do, and the death of fear is sure.

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  3. #3
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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 ....
    Last edited by ankurjain; 19th May 2006 at 09:28.
    Do what u r afraid to do, and the death of fear is sure.

  4. #4
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Column/Row no of ComboBox Widget in Table

    Yes sure but why dont want use currentColumn() or currentRow() method ?
    a life without programming is like an empty bottle

  5. #5
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default 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
    a life without programming is like an empty bottle

  6. #6
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Column/Row no of ComboBox Widget in Table

    hi all,

    hav a look at my code
    Qt Code:
    1. void QGrid::autoFilter()
    2. {
    3. int columnCount = this->columnCount();
    4. int rowCount = this->rowCount();
    5. QStringList filter;
    6. QString temp_string;
    7. QComboBox *newCombo;
    8. for(int c = 0;c<columnCount;c++)
    9. {
    10. for(int r = 1; r<rowCount;r++)
    11. {
    12. temp_string = this->item(r,c)->text();
    13. if(!filter.contains(temp_string))
    14. filter << temp_string;
    15. }
    16. filter << "None";
    17. newCombo = new QComboBox(this);
    18. newCombo->addItems(filter);
    19. newCombo->setCurrentIndex(filter.count()-1);
    20. this->setCellWidget(0,c,newCombo);
    21. filter.clear();
    22. connect(newCombo,SIGNAL(activated(const QString &)),this,SLOT(testAnother(const QString &)));
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 
    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 :



    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 ...
    Last edited by ankurjain; 19th May 2006 at 10:10.
    Do what u r afraid to do, and the death of fear is sure.

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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
    J-P Nurmi

  8. The following user says thank you to jpn for this useful post:

    ankurjain (19th May 2006)

  9. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Post Re: Column/Row no of ComboBox Widget in Table

    Qt Code:
    1. // set column index for combo boxes
    2. newCombo->setObjectName(QString::number(c));
    3.  
    4. // the slot
    5. void testAnother(const QString& text)
    6. {
    7. // retrieve column index of the sender of the signal
    8. int c = sender()->objectName().toInt();
    9. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  10. The following user says thank you to jpn for this useful post:

    ankurjain (19th May 2006)

  11. #9
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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 ....
    Do what u r afraid to do, and the death of fear is sure.

  12. #10
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default 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
    Qt Code:
    1. #ifndef _MY_COMBO_BOX_H
    2. #define _MY_COMBO_BOX_H
    3.  
    4. #include <qobject.h>
    5. #include <qcombobox.h>
    6.  
    7. //***********Defination of OdyComboBox****************
    8.  
    9. class CMyComboBox : public QComboBox
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. CMyComboBox ( int row, int column, QWidget * parent, const char * name = 0 ) ;
    15.  
    16. signals:
    17. void activated (int row, int column, const QString & string);
    18.  
    19. public slots:
    20. void reEmitActivated(const QString &);
    21.  
    22. private:
    23. int row;
    24. int column;
    25. };
    26.  
    27. #endif
    To copy to clipboard, switch view to plain text mode 

    and source File

    Qt Code:
    1. //***********Implementation of OdyComboBox****************
    2.  
    3. CMyComboBox::CMyComboBox (int row, int column, QWidget * parent, const char * name )
    4. : QComboBox( parent, name ), row(row), column(column) {
    5.  
    6. setPaletteBackgroundColor( Qt::white );
    7. connect( this, SIGNAL(activated (const QString &)), this, SLOT(reEmitActivated(const QString &) ));
    8. }
    9.  
    10. void CMyComboBox::reEmitActivated(const QString & string) {
    11. emit activated( row, column, string );
    12. }
    To copy to clipboard, switch view to plain text mode 

  13. The following user says thank you to sumsin for this useful post:

    ankurjain (23rd May 2006)

  14. #11
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Column/Row no of ComboBox Widget in Table

    hi sumsin,
    ur implementation was nice .... i got a bit confused in the code :

    Qt Code:
    1. CMyComboBox::CMyComboBox (int row, int column, QWidget * parent, const char * name )
    2. : QComboBox( parent, name ), row(row), column(column)
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. void CMyComboBox::reEmitActivated(const QString & string) {
    2. emit activated( row, column, string );
    3. }
    To copy to clipboard, switch view to plain text mode 

    here how u got the row and column ?

    i am a new user to this ..... so if its too easy, then also pls reply ....
    Do what u r afraid to do, and the death of fear is sure.

  15. #12
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Column/Row no of ComboBox Widget in Table

    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.

  16. The following user says thank you to munna for this useful post:

    ankurjain (23rd May 2006)

  17. #13
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Column/Row no of ComboBox Widget in Table

    Exactly. What munna says.
    Thanks munna.

  18. #14
    Join Date
    Sep 2011
    Posts
    20
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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
    Last edited by lekhrajdeshmukh; 6th December 2011 at 11:03.

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. Table Widget Vs. Table View
    By winston2020 in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2008, 09:56
  3. Replies: 4
    Last Post: 4th February 2008, 06:16
  4. customizing table widget
    By krishna.bv in forum Qt Programming
    Replies: 1
    Last Post: 25th January 2007, 13:43
  5. Dynamic updates to a table widget
    By guiGuy in forum Qt Programming
    Replies: 6
    Last Post: 1st June 2006, 20:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.