Results 1 to 6 of 6

Thread: Language Selector QCombobox question

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Question Language Selector QCombobox question

    Good morning to all, especialy nice and kind experts like wysota and jpn!!!

    Can I get some help, please? I need a QComboBox that act as language selector widget. I've written this (header):
    Qt Code:
    1. #ifndef CLANGUAGESETTINGSPAGE_H_
    2. #define CLANGUAGESETTINGSPAGE_H_
    3.  
    4. // qt includes
    5. #include <QtGui>
    6. #include <QVBoxLayout>
    7. #include <QHBoxLayout>
    8. #include <QPointer>
    9. #include <QString>
    10.  
    11. // custom includes
    12. #include "globals.h"
    13. class CLanguageSettingsPage : public QWidget
    14. {
    15. public:
    16. CLanguageSettingsPage(QWidget* pParent=0);
    17. ~CLanguageSettingsPage();
    18.  
    19. inline QPointer<QLabel> languageSelectorLB()
    20. { return m_pLangaugeSelectorLB; };
    21. inline QPointer<QComboBox> languageSelectorCB()
    22. { return m_pLanguageSelectorCB; };
    23. inline QPointer<QHBoxLayout> languageSelectorHBL()
    24. { return m_pLanguageSelectorHBL; };
    25.  
    26. private:
    27. QPointer<QLabel> m_pLangaugeSelectorLB; // lang. sel. label
    28. QPointer<QComboBox> m_pLanguageSelectorCB; // lang. sel. combo box
    29. QPointer<QHBoxLayout> m_pLanguageSelectorHBL; // lang. sel. horiz. layout
    30. };
    31.  
    32. #endif /*CLANGUAGESETTINGSPAGE_H_*/
    To copy to clipboard, switch view to plain text mode 
    and it's implementation:
    Qt Code:
    1. #include "CLanguageSettingsPage.h"
    2.  
    3. CLanguageSettingsPage::CLanguageSettingsPage(QWidget* pParent)
    4. : QWidget(pParent)
    5. {
    6. // language selector label
    7. m_pLangaugeSelectorLB=new QLabel(tr("Client default language:"), this); // creates new label
    8. Q_CHECK_PTR(m_pLangaugeSelectorLB); // checks creation
    9. //m_pLangaugeSelectorLB->setFrameStyle(QFrame::Panel | QFrame::Raised); // test
    10. // **** end oflanguage selector label
    11.  
    12. // language selector combo box
    13. m_pLanguageSelectorCB=new QComboBox(this); // creates new combo box
    14. Q_CHECK_PTR(m_pLanguageSelectorCB); // checks creation
    15. m_pLanguageSelectorCB->addItem("SlovenÅ¡čina");
    16. m_pLanguageSelectorCB->addItem("English");
    17. m_pLanguageSelectorCB->addItem("Deutsch");
    18. m_pLanguageSelectorCB->addItem("Italiano");
    19. m_pLanguageSelectorCB->addItem("Español");
    20. // **** end oflanguage selector combo box
    21.  
    22. // layout creation
    23. m_pLanguageSelectorHBL=new QHBoxLayout(); // creates new layout
    24. Q_CHECK_PTR(m_pLanguageSelectorHBL); // checks creation
    25. // adds widget to layout
    26. m_pLanguageSelectorHBL->addWidget(m_pLangaugeSelectorLB);
    27. // adds widget to layout
    28. m_pLanguageSelectorHBL->addWidget(m_pLanguageSelectorCB);
    29. // sets layout
    30. setLayout(m_pLanguageSelectorHBL);
    31. }
    32.  
    33. CLanguageSettingsPage::~CLanguageSettingsPage()
    34. {
    35. }
    To copy to clipboard, switch view to plain text mode 
    Everything works fine, however, language native charaters (in Slovenian language and Espanol) are not shown. How do I achieve so native characters will be shown?? I've attached a sscreenshot of a problem.
    Attached Images Attached Images
    Last edited by MarkoSan; 31st January 2008 at 06:05.
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Language Selector QCombobox question

    Your compiler treats the source as whatever it likes (either latin1 or utf-8 I guess) but there your native chars are no available / wrong.
    Don't use native chars in source code as you can never predict how (== which encoding) a specific compiler interprets the source.

  3. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Language Selector QCombobox question

    So, there is no solution to this problem? Then I simply must translate all languages into English (which is not a problem, but I would really like to know how to implement more than language support for further use).
    Qt 5.3 Opensource & Creator 3.1.2

  4. #4
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Language Selector QCombobox question

    use QTranslator to translate the english names into their native characters

  5. #5
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Language Selector QCombobox question

    Ok, will do so, but i do not like this solution, but can I use, QTextCodec class, do you have any experience with it?
    Qt 5.3 Opensource & Creator 3.1.2

  6. #6
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Language Selector QCombobox question

    QTextCodec can't help you here either - As I said you can't be sure what codec the compiler is using.
    But this can work:
    Qt Code:
    1. QString str = "Sloven" + QChar(0x1234) + QChar(0x1235) + "ina";
    To copy to clipboard, switch view to plain text mode 
    where 0x1234 and 0x1235 should be the correct unicode numbers for Å¡ and č .

  7. The following user says thank you to ChristianEhrlicher for this useful post:

    MarkoSan (31st January 2008)

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.