Important: Please read the Qt Code of Conduct -

How to let icon be on the left of the text if I use QListView and QStandardItemModel?

  • Hi, Sir:
    I study some articles to study these model.view and have a test application.
    However, no matter what I do, I can not get the result right.
    The icons are always on the top of the text instead of the left of text.
    So, Could you please teach me how to do that?

    QGridLayout * gridLayout = new QGridLayout(this);
    mListView = new QListView(this);
    mListView->setIconSize(QSize(24, 24));
    gridLayout->addWidget(mListView, 0, 0, 1, 1);

    mQStandardItemModel = new QStandardItemModel(this);@

    mQStandardItemModel->appendRow(new QStandardItem(QIcon(icon), a[i].at(1)));@

  • Set the view to list mode:


  • Hi, Volker:
    You are the best one!!
    Thanks for your help.

    I get it done now.

    But, I have another question.
    This is could I have the text aligned to right side if there is no icon in that row?

    Thanks again.


  • Well, there is always QStandardItem::setTextAlignment() that you could try?

  • Hi, Andre:
    Thanks a lot.
    After testing that, I think the ui feeling is not waht I want.
    So, I use a fake icon to make the row have "indent" feeling.

    Thanks again.

Log in to reply