Results 1 to 10 of 10

Thread: currentText in Qcombobox

  1. #1
    Join Date
    Jul 2012
    Location
    Chennai , India
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question currentText in Qcombobox

    How can i get the current text of Qcombobox in QtableWidget

  2. #2
    Join Date
    Mar 2012
    Location
    India
    Posts
    102
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: currentText in Qcombobox

    use the combobox.currentText() method.

  3. #3
    Join Date
    Jul 2012
    Location
    Chennai , India
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: currentText in Qcombobox

    it is not working because it is in the QtableWidget

  4. #4
    Join Date
    Mar 2012
    Location
    India
    Posts
    102
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: currentText in Qcombobox

    can u post the code snippet in question ?

  5. #5
    Join Date
    Jul 2012
    Location
    Chennai , India
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: currentText in Qcombobox

    int row=1;
    int col=8;
    QComboBox *com=new QComboBox(this);
    com->addItems(dislist);
    ui->widget->setCellWidget(row,col,com);


    Note:

    ui->widget - is QtableWidget,
    then how can i get the currentText in the Qcombobox

    Pls help me

    Thank U

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: currentText in Qcombobox

    Exactly the same way you do anywhere else, by using a pointer to the control:
    Qt Code:
    1. com->currentText();
    To copy to clipboard, switch view to plain text mode 
    You have to keep a pointer to the control to be able to do this.

  7. #7
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: currentText in Qcombobox

    Or (if you know what you are doing) you can use QTableWidget::cellWidget(), cast it to QComboBox and then use currentText(). But this may cause disaster when used incorrectly...

    Ginsengelf

  8. #8
    Join Date
    Jul 2012
    Location
    Chennai , India
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: currentText in Qcombobox

    i want to get the text of combobox in another function.
    can u pls explain me.
    How to code this

  9. #9
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: currentText in Qcombobox

    Check this out

    Qt Code:
    1. int row = 1;
    2. int col = 8;
    3. QStringList dislist;
    4. QComboBox* com = new QComboBox(this);
    5. com->addItems(dislist);
    6. ui->widget->setCellWidget(row, col, com);
    7.  
    8. //another function
    9. QComboBox* cell_com = dynamic_cast<QComboBox*>(ui->widget->cellWidget(1, 8));
    10. QString text;
    11. if(cell_com != 0)
    12. {
    13. text = cell_com->currentText();
    14. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  10. #10
    Join Date
    Jul 2012
    Location
    Chennai , India
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: currentText in Qcombobox

    its working !
    Thank U, Thank U,Thank U very much......

Similar Threads

  1. QComboBox BUG?
    By mak_user in forum Qt Programming
    Replies: 15
    Last Post: 18th September 2020, 08:00
  2. Set value to QComboBox
    By Archa4 in forum Newbie
    Replies: 2
    Last Post: 19th May 2011, 13:46
  3. Qcombobox
    By Project25 in forum Qt Programming
    Replies: 2
    Last Post: 16th December 2009, 20:29
  4. QComboBox
    By bismitapadhy in forum Qt Programming
    Replies: 7
    Last Post: 15th July 2009, 07:01
  5. QComboBox
    By coderbob in forum Qt Programming
    Replies: 4
    Last Post: 12th December 2007, 07:38

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.