Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to let icon be on the left of the text if I use QListView and QStandardItemModel?

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 6.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pico
    wrote on last edited by
    #1

    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->setEditTriggers(QAbstractItemView::NoEditTriggers);
    mListView->setIconSize(QSize(24, 24));
    mListView->setResizeMode(QListView::Adjust);
    mListView->setSpacing(1);
    mListView->setViewMode(QListView::IconMode);
    mListView->setFlow(QListView::TopToBottom);
    mListView->setWordWrap(true);
    mListView->setWrapping(false);
    gridLayout->addWidget(mListView, 0, 0, 1, 1);

    mQStandardItemModel = new QStandardItemModel(this);@
    

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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Set the view to list mode:

      @
      mListView->setViewMode(QListView::ListMode);
      @

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pico
        wrote on last edited by
        #3

        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.

        BR,
        Pico

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pico
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved