Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User Sasler's Avatar
    Join Date
    Jan 2010
    Posts
    272
    In QComboBox, how can I align the text to centre? Currently (in Maemo 5 at least) the text is aligned left.

    Also (again in Maemo 5) there is this "title" when it's open. How can I change that? Currently it's showing the app name only.

    Cheers

  2. #2
    Nokia Developer Moderator divanov's Avatar
    Join Date
    Oct 2009
    Posts
    4,326
    You can do something like this:
    Code:
    #include <QApplication>
    #include <QMainWindow>
    #include <QComboBox>
    #include <QAbstractItemView>
    #include <QDebug>
    
    int main(int argc, char* argv[])
    {
        QApplication app(argc,argv);
    
        QComboBox *combo = new QComboBox;
        combo->addItem("item1");
        combo->addItem("item2");
        combo->addItem("item3");
        combo->addItem("item4");
        QAbstractItemView *view = combo->view();
        QAbstractItemModel *model = view->model();
        model->setData(model->index(0, 0), QVariant(Qt::AlignCenter), Qt::TextAlignmentRole);
    
        QMainWindow w;
        w.setCentralWidget(combo);
        w.show();
    
        return app.exec();
    }

  3. #3
    Registered User biyu's Avatar
    Join Date
    Feb 2009
    Posts
    22
    Quote Originally Posted by divanov View Post
    You can do something like this:
    Code:
    #include <QApplication>
    #include <QMainWindow>
    #include <QComboBox>
    #include <QAbstractItemView>
    #include <QDebug>
    
    int main(int argc, char* argv[])
    {
        QApplication app(argc,argv);
    
        QComboBox *combo = new QComboBox;
        combo->addItem("item1");
        combo->addItem("item2");
        combo->addItem("item3");
        combo->addItem("item4");
        QAbstractItemView *view = combo->view();
        QAbstractItemModel *model = view->model();
        model->setData(model->index(0, 0), QVariant(Qt::AlignCenter), Qt::TextAlignmentRole);
    
        QMainWindow w;
        w.setCentralWidget(combo);
        w.show();
    
        return app.exec();
    }
    Hi Daniil,

    I tried your code in Qt4.7, and it seems not to work . The alignment is still "left" for all items in combobox. Actually I'm meeting the same problem when I try to modify the text alignment of combobox on N900 with maemo5 firmware 1.3. So do you have any other idea for solving this problem?

  4. #4
    Nokia Developer Moderator divanov's Avatar
    Join Date
    Oct 2009
    Posts
    4,326
    It works perfectly for me. Note that PR1.3 contains Qt 4.7, while Nokia Qt SDK 1.0.1 still has Qt 4.6. This mismatch can cause any deviations.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved