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. pixmap and text alignment in IconView

pixmap and text alignment in IconView

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 3.1k Views 2 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.
  • S Offline
    S Offline
    samdol
    wrote on last edited by p3c0
    #1

    alt text

    I have used QListView to show thumbnails. And set the stylesheet to adjust icons.

        QListView* iconView=new QListView;
        iconView->setViewMode(QListView::IconMode);
        iconView->setUniformItemSizes(true);
        iconView->setStyleSheet("QListView::item:deselected { border: 1px solid black; border-radius: 6px; color: black;} QListView::item:selected {background: white; border: 4px solid blue;}");
    

    As you can see, vertically the pixmap aligns to top of border and the text aligns to middle of rest space. You can see it clearly in the second icon. But I want the other way around.
    Can anyone tell me how I can change the alignment of pixmap and text so that first, the text is positioned to the bottom of border, and then the pixmap algins at the middle of the rest space?

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @samdol You can adjust the text using stylesheet as follows:

      "QListView::text{"
      "bottom: -4px;" //negative values
      "}"
      

      157

      S 1 Reply Last reply
      0
      • p3c0P p3c0

        @samdol You can adjust the text using stylesheet as follows:

        "QListView::text{"
        "bottom: -4px;" //negative values
        "}"
        
        S Offline
        S Offline
        samdol
        wrote on last edited by
        #3

        @p3c0
        I tried but the pixmap takes the top part of icon and the text still aligned middle of the rest of space.

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @samdol AFAIK these are the only ways to adjust the icon and text in listview items using stylesheets.

          QListView::text
          QListView::icon
          

          You can try setting padding-left, right, bottom and top or just left, right, top and bottom for adjusting their positions.
          More info here:
          http://doc.qt.io/qt-5/stylesheet-reference.html

          But in the end the best way is to create a custom delegate using QStyledItemDelegate.

          157

          S 1 Reply Last reply
          1
          • p3c0P p3c0

            @samdol AFAIK these are the only ways to adjust the icon and text in listview items using stylesheets.

            QListView::text
            QListView::icon
            

            You can try setting padding-left, right, bottom and top or just left, right, top and bottom for adjusting their positions.
            More info here:
            http://doc.qt.io/qt-5/stylesheet-reference.html

            But in the end the best way is to create a custom delegate using QStyledItemDelegate.

            S Offline
            S Offline
            samdol
            wrote on last edited by
            #5

            @p3c0
            I have tried
            QListView::text{bottom: -4px;}
            But it lowers down the text -4px from the center line of the rest space after icon. Thus if icons have different heights, meaning different reft over space after the icons, texts after them are not aligned horizontally. Some text is higher than other texts. I would like to have all the texts to be aligned at the bottom of the border.

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              @samdol Well then you are only left with using QStyledItemDelegate.

              157

              1 Reply Last reply
              1
              • P Offline
                P Offline
                peteritv
                wrote on last edited by
                #7

                Hi Sam,

                According to the docs,

                iconView->setUniformItemSizes(true);
                

                may only be set if items are indeed the same size.

                No idea if it will work, but try setting the gridSize instead...

                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