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. QListWidget Custom Widget, has more space on right side & Limit widget count for each line

QListWidget Custom Widget, has more space on right side & Limit widget count for each line

Scheduled Pinned Locked Moved Solved General and Desktop
qlistwidgetpyqtpyqt5pyqt6qwidget
4 Posts 3 Posters 1.1k Views
  • 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.
  • EmrecpE Offline
    EmrecpE Offline
    Emrecp
    wrote on last edited by
    #1

    Hello,
    listwidget.png
    I have QListWidget with red border.
    I am using this code to set custom widget;

    lblResim = QLabel()
    lblResim.setPixmap(QPixmap(':/avatars/img/Avatars/Adam1.png').scaled(QSize(128,128),Qt.KeepAspectRatio, Qt.SmoothTransformation))
    item = QListWidgetItem()
    listWidget.addItem(item)
    listWidget.setItemWidget(item, lblResim)
    item.setSizeHint(lblResim.sizeHint())
    
    1. Is there anyway to sync left and right space? (In picture, left side has 18 pixels space, right side has 72 pixels space, left and right should be has (72+18)/2 pixels space)
    2. As you see in picture, first and second line has 4 items/widgets. Is QListWidget has any function to set limit per line like listWidget.setCountPerLine(3) ?

    I hope it was understandable, Thanks!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You could check with the gridSize property.

      As for limiting the number of column, it looks like you might rather be looking for a QTableWidget.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        Also, why are you setItemWidget for just setting an image?

        listWidget.setViewMode(QListView::IconMode);
        item = QListWidgetItem();
        item.setData(Qt::DecorationRole, QPixmap(':/avatars/img/Avatars/Adam1.png'));
        listWidget.addItem(item);
        

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        EmrecpE 1 Reply Last reply
        3
        • VRoninV VRonin

          Also, why are you setItemWidget for just setting an image?

          listWidget.setViewMode(QListView::IconMode);
          item = QListWidgetItem();
          item.setData(Qt::DecorationRole, QPixmap(':/avatars/img/Avatars/Adam1.png'));
          listWidget.addItem(item);
          
          EmrecpE Offline
          EmrecpE Offline
          Emrecp
          wrote on last edited by
          #4

          @VRonin Yeah you are right. Usually my custom widget has another widgets (like another label for text, button for submit etc.) so I used setItemWidget. But your way better for only images.

          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