Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Delegate editor shows double text while editing

Delegate editor shows double text while editing

Scheduled Pinned Locked Moved General and Desktop
4 Posts 1 Posters 2.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pitonyak
    wrote on last edited by
    #1

    I have a table view, and I created my own QStyledItemDelegate.

    When I double click in a field that creates a text edit field, two sets of text are shown; the original and the new text that you are editing. The top portion of this image is how the Table looks before I double click in the cell to edit it. The bottom example shows the strange display.

    !http://www.pitonyak.org/QT_Bad_Delegate.png(Double Text)!

    Note that this used to work, and now it has this strange behavior. Sadly, I don't use this particular dialog often, so i am uncertain when it began. It may have been introduced with QT 5.0, and it may be related to my move from Fedora 17 to Fedora 18.

    This is how I define my delegate

    @class LinkBackFilterDelegate : public QStyledItemDelegate
    {
    Q_OBJECT
    public:
    explicit LinkBackFilterDelegate(QObject *parent = 0);

    /*! \brief Returns the widget used to edit the item specified by index for editing.

    • \param [in, out] parent Used to control how the editor widget appears.
    • \param [in] option Used to control how the editor widget appears.
    • \param [in] index Indicates which column is of interest.
    • \return Widget used to edit the specified data (so the editor is specific to the column).
      */
      QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
      const QModelIndex &index) const;
    /*! \brief Set the data into the editor for the location based on the mode.
     *  The data is obtained from the model.
     */
    void setEditorData(QWidget *editor, const QModelIndex &index) const;
    void setModelData(QWidget *editor, QAbstractItemModel *model,
                      const QModelIndex &index) const;
    
    void updateEditorGeometry(QWidget *editor,
        const QStyleOptionViewItem &option, const QModelIndex &index) const;
    

    signals:

    public slots:

    };
    @

    This is how I created my QLineEdit that causes the problem

    @QWidget *LinkBackFilterDelegate::createEditor(QWidget parent, const QStyleOptionViewItem &,
    const QModelIndex &index) const
    {
    QVariant qvar = index.model()->data(index, Qt::EditRole);
    if (qvar.type() == QVariant::StringList)
    {
    return new QComboBox(parent);
    }
    else if (qvar.type() == QVariant::Bool)
    {
    QCheckBox
    checkBox = new QCheckBox(parent);
    checkBox->setTristate(false);
    return checkBox;
    }
    return new QLineEdit(parent);
    }@

    Any thoughts?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      pitonyak
      wrote on last edited by
      #2

      Side note, I originally used QItemDelegate, and have gone back to it since I was not styling anything!.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pitonyak
        wrote on last edited by
        #3

        One final comment. I am able to avoid the problem using something like this, but it just feels wrong.

        @void LinkBackFilterDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
        {
        // This feels wrong, I should not need to do this, but, it works.
        // If I do not do this, then the underlying text box shows through to the
        // Editing text box.
        if ((current_state & (QStyle::State_Active | QStyle::State_HasFocus | QStyle::State_Selected)) == QStyle::State_Selected) {
        QItemDelegate::drawBackground( painter, option, index );
        } else {
        QItemDelegate::paint( painter, option, index );
        }
        }@

        1 Reply Last reply
        0
        • P Offline
          P Offline
          pitonyak
          wrote on last edited by
          #4

          No ideas? Well, here is the solution I finally settled on (since relying on the state will fail in some rare situations.... well, not that rare).

          @ //widget = new QLineEdit(parent);
          // Returns an expanding line editor.
          QWidget* widget = QStyledItemDelegate::createEditor(parent, option, index);

          // If I do not set this to true, then the "view" data shows through the text while editing.
          // Also, the expanding editor grows over existing controls, and you can see those through
          // the edit display as well (distracting).
          widget->setAutoFillBackground(true);
          return widget;@

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved