Results 1 to 1 of 1

Thread: Custom Delegate for QTableView in QCompleter not invoked

  1. #1
    Join Date
    Apr 2019
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Question Custom Delegate for QTableView in QCompleter not invoked

    Hello,

    i have a QLineEdit with a QCompleter which is used as a search bar. The customer now wants an icon to be displayed at the end of each completer row, but only when the entry is highlighted or when the mouse is hovering over it.
    I tried to achieve this by overriding the paint method of a custom delegate derived from QStyledItemDelegate, as I have done it before with a QTreeView.

    I basically duplicated the procedure for installing the delegate but the overridden methods dont get invoked at all.

    Qt Code:
    1. ptrModel = new QStandardItemModel();
    2.  
    3. ptrView = new QTableView();
    4. ptrDelegate = new SearchBarDelegate();
    5. ptrView->verticalHeader()->setVisible(false);
    6. ptrView->horizontalHeader()->setVisible(false);
    7. ptrView->setSelectionBehavior(QTableView::SelectRows);
    8. ptrView->setShowGrid(false);
    9.  
    10. ptrView->setItemDelegate(ptrDelegate);
    11.  
    12. ptrCompleter = new QCompleter(ptrModel, this);
    13. ptrCompleter->setCompletionColumn(0);
    14. ptrCompleter->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
    15. ptrCompleter->setCaseSensitivity(Qt::CaseInsensitive);
    16. ptrCompleter->setMaxVisibleItems(amountSearchRecommendations);
    17.  
    18. ptrCompleter->setPopup(ptrView);
    19.  
    20. setCompleter(ptrCompleter);
    To copy to clipboard, switch view to plain text mode 

    and the delegate class looks like this

    Qt Code:
    1. class SearchBarDelegate : public QStyledItemDelegate
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. SearchBarDelegate(QWidget *parent = Q_NULLPTR) :
    7. QItemDelegate(parent)
    8. { }
    9.  
    10. void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
    11. QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
    12. };
    To copy to clipboard, switch view to plain text mode 

    I tried to subclass it from QItemDelegate, QAbstractItemDelegate but to no avail.

    thx in advance
    Last edited by flautzr; 23rd June 2020 at 17:12.

Similar Threads

  1. How to do QChartView delegate like QTableView item delegate
    By malleeswarareddy.s in forum Qt Programming
    Replies: 0
    Last Post: 16th September 2015, 12:37
  2. qtableview qcompleter
    By Cremers in forum Qt Programming
    Replies: 6
    Last Post: 10th May 2014, 19:56
  3. Replies: 15
    Last Post: 11th December 2012, 21:10
  4. Custom Model? Custom View? Custom Delegate?
    By Doug Broadwell in forum Newbie
    Replies: 4
    Last Post: 11th February 2010, 21:23
  5. Replies: 0
    Last Post: 1st February 2010, 12:00

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.