Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    qlistwidget pyqt pyqt5 pyqt6 qwidget
    3
    4
    280
    Loading More Posts
    • 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.
    • Emrecp
      Emrecp last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 2
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          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 Reply Quote 2
          • V
            VRonin last edited by

            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

            Emrecp 1 Reply Last reply Reply Quote 3
            • Emrecp
              Emrecp @VRonin last edited by

              @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 Reply Quote 0
              • First post
                Last post