1

I have a simple QStandardItem and QTableView and QStyledItemDelegate. They have delegates , I would like to disable the possibility for user to change the content of a column in the table, and allow only select and copy. I guess it related to QStyledItemDelegate::createEditor.

When I set it to return 0, it just disable everything.

QWidget *InfoTableItemDelegate::createEditor(QWidget *parent,
                                    const QStyleOptionViewItem &option,
                                    const QModelIndex &index) const
{
    // return QStyledItemDelegate::createEditor(parent, option, index);
    return 0;
}

my question is , how can i defined it so i can only select and copy , and disable the option to edit it like delete or change the text

user63898
  • 29,839
  • 85
  • 272
  • 514
  • 1) Don't forget to write your question... 2) What is "disable everything"? 3) Returning 0 should be ok here, it doesn't create editor widget so you cannot edit the model. – Synxis Nov 28 '12 at 10:08
  • thanks , all i want to be able to select and copy the text , but not edit it ( delete or change ) when i do this with return 0, i can't select and copy it – user63898 Nov 28 '12 at 11:32

1 Answers1

1

If your data can be showed as simple text, then you can return a QLineEdit in read-only mode. If you have images or other types of data, maybe a selectable QLabel with some html in it (to make a QLabel selectable, you have to include Qt::TextSelectableByMouse or Qt::TextSelectableByKeyboard in the label's interaction flags).

Synxis
  • 9,236
  • 2
  • 42
  • 64
  • 1/ That's not a very constructive comment. 2/ Why do you think it's not a good way to do this ? 3/ You cannot select directly, it is not implemented in Qt. The other way is to write a delegate that keeps track of the mouse and paint the widget accordingly, which is much more work I think. – Synxis Nov 29 '12 at 10:03
  • sorry for the comment . but i guess by now if i use delegate for the table i can do it with setting flags – user63898 Nov 29 '12 at 10:55