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. [solved] How to remove the sizeHint() previously applied?
Forum Updated to NodeBB v4.3 + New Features

[solved] How to remove the sizeHint() previously applied?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.2k 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.
  • A Offline
    A Offline
    alexandros
    wrote on last edited by
    #1

    Hello there :) In my listwidget items I have set a custom size hint. After some user actions I want to remove this sizeHint and go back to the default one.

    More specifically, I want to be able to convert my list view mode from IconMode to ListMode. My listwidget items, when IconMode is enabled have a custom size hint. When the user switches back to the ListMode I want to revert back to the default sizeHint. As I saw, the default sizeHint is QSize(-1, -1), but, if I set every item to this sizeHint, then nothing shows up (the items seem to disappear).

    In case this is helpful, when I am at IconMode, my items have icon and when I switch to the ListMode I make sure to remove this icon via:
    @ui->listWidget->item(i)->setIcon(QIcon(""));@

    Can someone point me to the right direction?

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

      Wouldn't it make more sense to use different delegates instead? Changing your actual data to change the display mode doesn't sound like the best approach...

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alexandros
        wrote on last edited by
        #3

        [quote author="Andre" date="1347788270"]Wouldn't it make more sense to use different delegates instead? Changing your actual data to change the display mode doesn't sound like the best approach...[/quote]

        It is a quick one and it works just fine :)

        Soooo, the answer is: You cannot do it?

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

          I did not say that. What you could try, is this:
          @
          ui->listWidget->item(i)->setData(Qt::SizeHintRole, QVariant());
          @

          Note that I did not try this myself, so it might not work. Also note that you should check if item(i) returns a valid pointer before dereferencing it.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            alexandros
            wrote on last edited by
            #5

            [quote author="Andre" date="1347806462"]I did not say that. What you could try, is this:
            @
            ui->listWidget->item(i)->setData(Qt::SizeHintRole, QVariant());
            @

            Note that I did not try this myself, so it might not work. Also note that you should check if item(i) returns a valid pointer before dereferencing it.[/quote]

            It works perfectly. How did you find this solution? I couldn't locate it at the documentation.

            Thanks a lot!

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

              It comes from understanding the model/view structure. QVariant() is the default non-valid value that is used in the model/view structure of Qt. You might read about that in the documentation for [[doc:QAbstractItemModel]]. What that call does is reset the SizeHint role to the default 'invalid' value, allowing the default delegate to take over that work again. Recognize that QListWidget is just a thin layer around a QStandardItemModel (or something a lot like it) and QListView.

              Anyway: you're welcome!

              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