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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:29:52+00:00 2026-06-10T15:29:52+00:00

I want to implement a table filled with data via QTableView. My problem is

  • 0

I want to implement a table filled with data via QTableView. My problem is that I don’t know how to remove the checkboxes from the cells. It seems like they are put in by default.

However, I read that I had to return a NULL-QVariant, but that’s not what I was looking for as I still have data to put in.

QVariant MyModel::data(const QModelIndex &index, int role) const
{
    int row = index.row();
    int col = index.column();
    QString daten;
    
    switch (col)
    {
    case 0:
    {
        daten = "column 1";
        break;
    }
    case 1:
    {
        daten = "column 2";
        break;
    }
    case 2:
    {
        daten = "column 3";
        break;
    }
    case 3:
    {
        daten = "column 4";
        break;
    }
    }
    
    return daten;
}

Now, as you can see, I want to fill the cell with the QString called daten. But next to the string, there is a Checkbox in every cell.

How do I remove the checkbox, but still fill the content with daten?

  • 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-10T15:29:54+00:00Added an answer on June 10, 2026 at 3:29 pm

    The fact that the cells in your QTableView have some checkbox hint that they were defined as user-checkable. Check whether you don’t have a Qt.ItemIsUserCheckable flag activated somewhere in the definition of your QTableView, and if that’s the case, deactivate it. You could try to modify the flags method, for example, forcing every entry not to be checkable

    As an additional comment, you should probably modify your ::data method to take into account the case where index is invalid and to return some value only if the role corresponds to Qt.DisplayRole. In Python, the syntax would be

    if index.isvalid():
        if (role == Qt.DisplayRole):
            (row, col) = (index.row(), index.column()
            return_something_depending_on_col
        return QVariant()
    return QVariant()
    

    That way, you cover the case of an invalid index, your code would likely crash otherwise.

    The test on role allows you to choose which type of data you want to access. The documentation states for example that:

    Each item in the model has a set of data elements associated with it, each with its own role. The roles are used by the view to indicate to the model which type of data it needs. Custom models should return data in these types.

    The basic role is Qt.DisplayRole, where you return the QString corresponding to your current cell. You could also return a QBrush for painting the background if your role is Qt.BackgroundRole…

    While not mandatory, these tests on role are still highly encouraged: it makes your code cleaner and easier to maintain.

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

Sidebar

Related Questions

Goal: I want to implement a hard-coded lookup table for data that doesn't change
I want to implement a basic search/replace translation table in C; that is, it
I want to implement some sort of lookup table in C++ that will act
I want to implement a simple in-house table that tracks user page views on
I have written a code that searches specific string from database table.what i want
I want to implement a vertical UITableView whose cells contain horizontally scrolling table views.
I want to implement a table with one column, or maybe a list in
I want to implement the following constraints in mysql: create table TypeMapping( ... constraint
I want to implement a ContentProvider that manipulates multiple tables. Here is what I
Microsoft has announce that WindowsLiveID become a OpenID provider . I want implement it

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.