Results 1 to 5 of 5

Thread: QComboBox problem

  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 QComboBox problem

    Hi,

    I have this code on "on_TextComboBox_textChanged(const QString &qText)" slot
    Qt Code:
    1. ui.TextComboBox->setCompleter(0);
    2. ui.TextComboBox->setEditable(false); //To not let the combo emit "textChanged"
    3. ui.TextComboBox->clear();
    4. //Fill the combo with the list elements
    5. if (!qLList.isEmpty())
    6. for (int i = 0; i < qLList.size(); ++i)
    7. ui.TextComboBox->addItem(QObject::tr(qLList.at(i).toAscii().data()));
    8.  
    9. //Adding the text written by hand on the combo
    10. ui.TextComboBox->addItem(qText);
    11. if (m_pCParameter->isEditable())
    12. ui.TextComboBox->setEditable(true);
    To copy to clipboard, switch view to plain text mode 

    It crashes when exits the slot on "QCompleter::completionMode()" function.

    What I want is a Combo that contains some items and the combo also have to be editable. So, when the user starts writting I want to insert the text as an item. For doing this I clear the items, add the items and finally add the text written as item. I don't want the completer so I try to disable it calling "ui.TextComboBox->setCompleter(0);".

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QComboBox problem

    How does that differ from a simple editable combobox? Your current solution won't work as you are modifying the state of the combo from within a slot connected to a signal emited as a result of a change of the combobox itself causing other slots connected to the same signal to malfunction.

  3. #3
    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,

    Sorry, I forget to tell you that I'm modifying internal data. I have a own class that is getting the text written on the combo.

    Qt Code:
    1. m_pCParameter->setText(qText);
    To copy to clipboard, switch view to plain text mode 
    Òscar Llarch i Galán

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QComboBox problem

    What is m_pCParameter and how is it related to ui.TextComboBox?

  5. #5
    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 12: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, 11:22
  2. Problem with QComboBox
    By jogeshwarakundi in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 8th December 2007, 14:21
  3. QComboBox drop list button events
    By maird in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2007, 20:25
  4. Replies: 16
    Last Post: 7th March 2006, 16: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.