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 update QListWidgetItem geometry.
QtWS25 Last Chance

How to update QListWidgetItem geometry.

Scheduled Pinned Locked Moved Solved General and Desktop
qlistwidgetqlistwidgetitemqwidgetgeometry
5 Posts 4 Posters 4.0k 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.
  • T Offline
    T Offline
    tokafr
    wrote on 13 Mar 2017, 11:41 last edited by
    #1

    Hello
    I am using QListWidget to have a list of widgets. to fill this list I use QListWidgetItem and set sizeHint to it.

    listWidget_ = new QListWidget(this);
    
    void addWidgetToList(QWidget *widget)
    {
        QListWidgetItem wItem  = new QListWidgetItem(listWidget_);
        wItem -> setSizeHint(widget -> sizeHint());
        listWidget_ -> addItem(wItem);
        wItem -> setItemWidget(widget);
    }
    

    on other part of code I need to change the sizeHint of items and I set different sizeHints to all items in list.
    but they don't update the geometry but wItem -> sizeHint() shows new correct value.
    I tried to call update, layout() -> invalidate/activate, updateGeometry repaint but they didn't affect.
    any idea?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      m.sue
      wrote on 14 Mar 2017, 13:14 last edited by
      #2

      Hi,
      it will probably work if you remove the item and add it again with the different size hint.
      -Michael.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 14 Mar 2017, 22:07 last edited by
        #3

        Hi,

        Why not use a QScrollArea for that ?

        A container QWidget with a QVBoxLayout on it and you have pretty much the behavior you want without having to play with the item size hint.

        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
        1
        • V Offline
          V Offline
          VRonin
          wrote on 15 Mar 2017, 08:44 last edited by
          #4

          The widget sizeHint is probably not that important to the QListWidget.

          It might be worth switching to a custom delegate instead... see QStyledItemDelegate

          "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

          1 Reply Last reply
          1
          • T Offline
            T Offline
            tokafr
            wrote on 15 Mar 2017, 10:00 last edited by tokafr
            #5

            Well seems that it needs to emit model's layoutChanged() to do what I need. I created new class which inherits QListWidget and there I connected signal to layoutChanged signal of model() object and it worked.

            1 Reply Last reply
            0

            1/5

            13 Mar 2017, 11:41

            • Login

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