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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:43:23+00:00 2026-05-14T16:43:23+00:00

I have a custom type I’d like to use with QVariant but I don’t

  • 0

I have a custom type I’d like to use with QVariant but I don’t know how to get the QVariant to display in a table or have it sort in a QSortFilterProxyModel.

I register the type with Q_DECLARE_METATYPE and wrote streaming operators registered via qRegisterMetaTypeStreamOperators but for whatever reason when I use the type with a table model, it doesn’t display anything and it doesn’t sort.

I should specify that this custom type can not be modified. It has a copy and default constructor, but I can not go in and modify the source code to get it to work with QVariant. Is there a way of non-intrusively getting the behaviour I’d like?

  • 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-14T16:43:24+00:00Added an answer on May 14, 2026 at 4:43 pm

    Display:

    It sounds like your model isn’t returning sensible content for the DisplayRole. The QAbstractItemDelegate (often a QStyledItemDelegate) that is used to display all content from the model needs to understand how to render the content of returned by data() for the Qt::DisplayRole.

    You have two main options:

    1. Modify your model so that it returns a sensible Qt::DisplayRole, OR
    2. Subclass one of the existing delegates and modify it so that it can display your custom variant type correctly.

    If you want to edit items of that type, you’ll need to call registerEditor so you can associate your custom type to an editor. See the QItemEditorFactory documentation.

    Sorting:

    You can’t rely on the comparison operator for QVariant as it doesn’t work with custom types, so you’ll need to implement QSortFilterProxyModel::lessThan to have custom sorting.

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

Sidebar

Related Questions

I use NHibernate and have a custom type for encrypting passwords in the database
I have a custom control type like: <Grid> ... </Grid> and Grid.BitmapEffect property. How
I have a custom type in my model like so: [StringLength(1000, MinimumLength = 150,
I have a custom c# type like (just an example): public class MyVector {
Lets say I have a custom data type that looks something like this: public
I have some custom type: [RdfSerializable] public class Item { [RdfProperty(true)] public string Name
Using NH 2.0, I have a custom type. It is composed of four properties,
I have a custom post type FAQ and custom taxonomy Category. I want to
We have a custom LocalizedString type used in our domain model. We want to
I have a custom content type create in visual studio 2010: custom http://img204.imageshack.us/img204/439/customf.jpg Here

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.