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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:52:40+00:00 2026-05-31T07:52:40+00:00

I want to set an editable column in QTableView , so far I tried

  • 0

I want to set an editable column in QTableView, so far I tried to subclass QTableView and reimplementing Qt::ItemFlags flags(const QModelIndex & index) const, subclassing QSqlQueryModel and reimplementing Qt::ItemFlags flags(const QModelIndex & index) const, finally, subclassing QAbstractItemView, but this make a compiler error showed up.

Subclassing QTableView:

#include "exqtableview.h"

ExQTableView::ExQTableView(QWidget *parent) :
    QTableView(parent)
{
}

Qt::ItemFlags ExQTableView::flags(const QModelIndex & index) const
{
    if (!index.isValid())
        return Qt::ItemIsEnabled;
    if (index.column() == 2)
        return index.parent().flags() & ~Qt::ItemIsEditable;
}

Sub classing QSqlQueryModel

#include "exsqlquerymodel.h"

ExSqlQueryModel::ExSqlQueryModel(QObject *parent) :
    QSqlQueryModel(parent)
{
}

Qt::ItemFlags ExSqlQueryModel::flags( const QModelIndex &index) const
{
    Qt::ItemFlags flags = QSqlQueryModel::flags(index);
    if (index.column() == 2 )
        flags &= ~Qt::ItemIsEditable;
    return flags;
}

Sub classing QAbstractItemView

#include "exitemdelegate.h"
#include <QTableWidgetItem>

ExItemDelegate::ExItemDelegate(QObject *parent) :
    QItemDelegate(parent)
{
}

QWidget *ExItemDelegate::createEditor(QWidget *parent,
    const QStyleOptionViewItem & ,
    const QModelIndex & index ) const
{
    QTableWidgetItem *item = new QTableWidgetItem;
    return item;
}

void ExItemDelegate::setEditorData(QWidget *editor,
                                     const QModelIndex &index) const
 {
     float value = index.model()->data(index, Qt::EditRole).toFloat();

     QTableWidgetItem *cell = static_cast<QTableWidgetItem*>(editor);
     cell->setData(0, value);
 }

void ExItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
                                    const QModelIndex &index) const
 {
     QTableWidgetItem *cell = static_cast<QTableWidgetItem*>(editor);
     float value = cell->data(Qt::DisplayRole);
     model->setData(index, value, Qt::EditRole);
 }

void ExItemDelegate::updateEditorGeometry(QWidget *editor,
    const QStyleOptionViewItem &option, const QModelIndex &) const
{
    editor->setGeometry(option.rect);
}

Why all of this methods fails to achieve what I want?

  • 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-31T07:52:42+00:00Added an answer on May 31, 2026 at 7:52 am

    To make one column editable you should add the editable flag, not remove it:

    flags |= Qt::ItemIsEditable;
    

    The flags() function belongs to the model class, not the view, and you also have a complete Qt example that shows how to make a QSqlQueryModel editable

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

Sidebar

Related Questions

I want to set the maxChars property of the TextInput of an editable ComboBox.
I want set interfaceOrientation in one UIView as LandscapeLeft and Portrait in other UIView.
i want set the visibility to itemized overlay in map view. if the zoom
I want set Listbox background to transparent but not working Is there any idea?
I want to set something up so that if an Account within my app
I want to set all the fields and labels on a VFP7 report to
I want to set a background image for a div, in a way that
I want to set a breakpoint on the __DoPostBack method, but it's a pain
I want to set up a Subversion server installation on Windows Server 2003 64-bit
I want to set some attributes just before the object is serialized, but as

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.