Results 1 to 5 of 5

Thread: QComboBox problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox problem

    Hi,

    "m_pCParameter" is a pointer to own class. This class contains a QList that is a list of possibilities that is used to fill the combo. Then I let the user choose one of this elements or to write a different text.

    The possibilities are saved untranslated on the QList possibilitites and translated when are inserted to the combo, but when the user selects an item, the internal object needs to save the untranslated text.
    So in "on_TextComboBox_textChanged(const QString &qText)" slot I use this code:

    Qt Code:
    1. [LEFT]ParametreTextWidget::on_TextComboBox_textChanged(const QString &qText)
    2. {
    3. int iIndex = ui.TextComboBox->findText(qText,Qt::MatchFixedString | Qt::MatchCaseSensitive);
    4. if (iIndex != -1)
    5. {
    6. QStringList qList = m_pCParameter->getList();
    7. if (!qList.empty())
    8. {
    9. QString qOriginalText = qList.at(iIndex);
    10. m_pCParameter->setText(qOriginalText);
    11. }
    12. else
    13. {
    14. m_pCParameter->setText(qText);
    15. }
    16. }
    17.  
    18. else
    19. {
    20. ui.[COLOR=#009900]TextComboBox[/COLOR]->setCompleter[COLOR=#000000]([/COLOR][COLOR=#0000dd]0[/COLOR][COLOR=#000000])[/COLOR];
    21. ui.[COLOR=#009900]TextComboBox[/COLOR]->setEditable[COLOR=#000000]([/COLOR][COLOR=#0000ff]false[/COLOR][COLOR=#000000])[/COLOR]; [COLOR=#ff0000]//To not let the combo emit "textChanged"[/COLOR]
    22. ui.[COLOR=#009900]TextComboBox[/COLOR]->clear[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]; [COLOR=#ff0000]//Fill the combo with the list elements[/COLOR]
    23. [COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]!qLList.[COLOR=#009900]isEmpty[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR]
    24. [COLOR=#0000ff]for[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000ff]int[/COLOR] i = [COLOR=#0000dd]0[/COLOR]; i < qLList.[COLOR=#009900]size[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]; ++i[COLOR=#000000])[/COLOR]
    25. ui.[COLOR=#009900]TextComboBox[/COLOR]->addItem[COLOR=#000000]([/COLOR][URL="http://doc.trolltech.com/latest/QObject.html"]QObject[/URL]::[COLOR=#009900]tr[/COLOR][COLOR=#000000]([/COLOR]qLList.[COLOR=#009900]at[/COLOR][COLOR=#000000]([/COLOR]i[COLOR=#000000])[/COLOR].[COLOR=#009900]toAscii[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR].[COLOR=#009900]data[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR];[COLOR=#ff0000] //Adding the text written by hand on the combo[/COLOR]
    26. ui.[COLOR=#009900]TextComboBox[/COLOR]->addItem[COLOR=#000000]([/COLOR]qText[COLOR=#000000])[/COLOR];
    27. [COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]m_pCParameter->isEditable[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR]
    28. ui.[COLOR=#009900]TextComboBox[/COLOR]->setEditable[COLOR=#000000]([/COLOR][COLOR=#0000ff]true[/COLOR][COLOR=#000000])[/COLOR];
    29.  
    30. [/LEFT]
    To copy to clipboard, switch view to plain text mode 
    What I try to do if the item is handwritten(not exist on the possibility list) is to insert it as a item and save it to internal object.

    Thanks,
    Last edited by ^NyAw^; 31st March 2008 at 11:46. Reason: Removing HTML tags(copy paste ...)
    Òscar Llarch i Galán

Similar Threads

  1. Problem while using QComboBox
    By merry in forum Qt Programming
    Replies: 6
    Last Post: 20th December 2007, 10:22
  2. Problem with QComboBox
    By jogeshwarakundi in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 8th December 2007, 13:21
  3. QComboBox drop list button events
    By maird in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2007, 19:25
  4. Replies: 16
    Last Post: 7th March 2006, 15:57

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
  •  
Qt is a trademark of The Qt Company.