Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6847103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:42:15+00:00 2026-05-27T00:42:15+00:00

I have a multiple-selection enabled QListView with an Item delegate (QStyledItemDelegate) I use for

  • 0

I have a multiple-selection enabled QListView with an Item delegate (QStyledItemDelegate) I use for setting the size for items and doing custom paint. My requirements are extremely simple:

  1. Row height 30 for non selected items
  2. Row height 60 for selected items

Can’t get this to work.

Tried using the sizeHint on my QStyledItemDelegate

if (option.state & QStyle::State_Selected)
{
  return QSize(100,60);   /// <<<<------ NEVER REACHED
}
else
{
  return QSize(100,30);
}

The state is never selected which is weird because the same if statement works perfectly for the painting method on the same class, distinguishing between selected rows and non-selected rows for different paint background.

Then I tried something else

I made the selection model (QItemSelectionModel) accessible to the sizeHint method on my delegate. Using this I can query successfully if the row the sizehint is called for is selected or not and I am returning the correct size. However now only the drawing is done in the correct variable size. for selected items, the drawing now has a height of 60, which is correct, but it overlaps the items underneath it. In other words: the new sizeHint size is used only for DRAWING, but not for actually making the QListView item taller. It seems there is a missing call to “update” the listView that one of its items has changed in size. I don’t need just to draw the item taller, i need the item to be taller for that purpose.

It seems that the sizeHint only has influence on the item height at the beginning when everything is initialized. if you all of a sudden return a higher height value for one of the items from your sizeHint — it won’t augment the listview to accommodate the new height.

One interesting observation:

If I set setResizeMode(QListView::Adjust) on my QListView, a slight resize to the control will trigger a re-calc of all the items, fixing the size of the actual selected item such the drawing (which is always done in the correct height) doesn’t cascade over the item beneath as the item height is now correct. This is what I need to do as selection changes, cause a “re-calc” like the QLiustView::Adjust causes. How do I do that?

What I’m doing now is ugly, and I’m positive it’s not way to do this, but I have no other alternative. I am hooking up to the selection model — listening on selection changes, and when they come, i resize my QlistView’s height by 1 and then go back to the original size. This generates a recalculation of the item sizes (setResizeMode(QListView::Adjust) and everything looks and works fine. I just get nauseous by having to do this– is there no better way to cause the items to re-calc their height NOT by faking a resize of the QListView?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:42:15+00:00Added an answer on May 27, 2026 at 12:42 am

    Confirmed with top Nokia Qt developers – The hack I’m doing apparently is the only way to get this thing done:

    What I’m doing now is ugly, and I’m positive it’s not way to do this,
    but I have no other alternative. I am hooking up to the selection
    model — listening on selection changes, and when they come, i resize
    my QlistView’s height by 1 and then go back to the original size. This
    generates a recalculation of the item sizes
    (setResizeMode(QListView::Adjust) and everything looks and works fine
    .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multiple selection listbox in which I insert items using javascript. At
I have a WPF ListBox that I would like to Enable multiple selection in
I have a multiple selection SELECT field which I don't want the end user
I have a registration form with common registration fields and two multiple selection Lists
I want to have a element that displays in the multiple selection display style
We have multiple MFC apps, which use CMutex( false, blah ), where blah allows
I have the following scenario. I have a combobox where multiple selection is available.
I have an ASP.NET WebForm with a number of DropDownLists, multiple select enabled ListBoxes,
Given a scenario where we have multiple lists of pairs of items, for example:
I have a multiple selection wxListBox and I want to keep the condition that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.