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 8359797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:15:50+00:00 2026-06-09T11:15:50+00:00

Is this even possible in Qt? I have a QListWidget setup with a delegate

  • 0

Is this even possible in Qt? I have a QListWidget setup with a delegate for specific painting, and I’m attempting to have the delegate paint differently based on variables in my QListWidget’s parent. I figure I can rig something up as long as I have a pointer to either, but I need to somehow get them while in the delegate’s paint().

I’ve tried the “hack” to store a pointer in a QVariant, but it doesn’t seem to be working, and I’d rather not take this approach. If I could get to the pointer to item the delegate represents, and just call item->listWidget(), this would be perfect, but it doesn’t seem possible while inside the delegate.

Is there any workaround to accomplish this?

Also, just because.. sample of trying to get the void* trick to work – if this is the only way to do this, perhaps someone may see what I have wrong in it.

//Parent of QListWidget
....
QListWidgetItem *item = new QListWidgetItem();
....
QVariant v = qVariantFromValue((void *) pStitchSymbolCustom);
item->setData(Qt::UserRole + 6, v);
....


//Implemented QAbstractItemDelegate
....
MyClass* p_pointer = 
    (MyClass*)(index.data(Qt::UserRole + 6).value<void *>());
  • 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-06-09T11:15:52+00:00Added an answer on June 9, 2026 at 11:15 am

    I’m not sure, if i understood your question correctly, but if you want to access the QListWidget wich contains your delegate, then i think, that the easiest way is to set the parent of the delegate as the listwidget, and then get the listwidget at any point of the delegate:

    QAbstractItemDelegate * delegate = new MyItemDelegate(myListWidget);
    
    myListWidget.setItemDelegate(delegate);
    

    and then in the delegate code:

    QListWidget * listWidget = qobject_cast<QListWidget*>(parent());
    
    //You can do whatever you want your list here
    

    If your object tree is deep, and you want the code to be generic and not care about where the desired parent is, you should ascend the tree automatically:

    QListWidget * listWidget = 0;
    QObject * object = parent();
    while (object && ! listWidget) {
        // qobject_cast will succeed once the parent of the correct type is reached
        listWidget = qobject_cast<QListWidget*>(object);
        object = object->parent();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is this even possible without calling a specific package? I have found countless examples
Is this even possible? I have a key-pair that I already made with GPG
I have no idea how this works or if it is even possible but
Im having issues getting this to work, maybe its not even possible? I have
I'm really unsure if this is even possible but we have an issue where
Is this even possible? Here's the problem: I have a keyword search with this
Is this even possible? I have a Rails app running on Passenger and a
Is this even possible... Say I have some text with a link with a
Is this even possible? basically I have a c++ application which sends packed 32
Is this even possible? For example, say I have an array of Dogs. How

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.