Results 1 to 2 of 2

Thread: how to suppress model::data DecorationRole when the QTableView cell editor is active

  1. #1
    Join Date
    Aug 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default how to suppress model::data DecorationRole when the QTableView cell editor is active

    I have a delegate to create a QLineEdit control when you want to edit a cell in my subclass of QTableView. In the data function of my model, I recently added a case to return an icon for Qt:ecorationRole for some items.

    As the user edits a cell that has an icon, the value they enter may cause the icon to disappear. That is all working correctly.

    The problem is, if the icon disappears as the user is still typing in the cell, my QLineEdit control is still sized as if there were an icon in the cell, but since there is no longer an icon, part of the text that the user is typing is displayed where the icon used to be.

    So, I'd like to have my delegate size the QLineEdit editor to fill the whole cell even when an icon is present (so the icon would be invisible when editing), or even better I think, have the delegate suppress anything returned for Qt:ecorationRole when editing.

    Currently, my delegate has these functions:

    QWidget *MapTextDelegate::createEditor(QWidget *parent,
    const QStyleOptionViewItem & /*option*/,
    const QModelIndex & /*index*/) const {
    QLineEdit *line_editor;
    line_editor = new QLineEdit(parent);
    connect(line_editor, SIGNAL(textChanged(QString)),
    this, SLOT(MapTextChanged()));
    return line_editor;
    }

    QSize MapTextDelegate::sizeHint(const QStyleOptionViewItem &/*option*/,
    const QModelIndex &/*index*/) const
    {
    QLineEdit *line_editor = new QLineEdit();
    return line_editor->sizeHint();
    }
    I don't see anything else in the delegate that might have to do with the size of the editor. I'm not too familiar with how to use delegates - actually, I'm pretty new to C++ and Qt.

    Any ideas? I'm using Qt 4.7.

  2. #2
    Join Date
    Aug 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to suppress model::data DecorationRole when the QTableView cell editor is act

    Turns out to be very easy. I reimplemented updateEditorGeometry in the delegate as follows, and that took care of it!

    Qt Code:
    1. void MapTextDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const {
    2. QStyledItemDelegate::updateEditorGeometry(editor, option, index);
    3. editor->setGeometry(option.rect);
    4. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 9
    Last Post: 14th February 2013, 19:39
  2. Replies: 0
    Last Post: 2nd October 2009, 17:57
  3. how to get data from cell of QTableview
    By yleesun in forum Qt Programming
    Replies: 2
    Last Post: 9th January 2009, 14:31
  4. Model/View framework: streaming data in a QTableView
    By yannickt in forum Qt Programming
    Replies: 6
    Last Post: 24th October 2008, 00:06
  5. Replies: 2
    Last Post: 5th February 2008, 14:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.