Results 1 to 2 of 2

Thread: Custom QStyledItemDelegate (QToolButton) - hovering instead of edit

  1. #1
    Join Date
    Sep 2010
    Location
    Germany
    Posts
    28
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Custom QStyledItemDelegate (QToolButton) - hovering instead of edit

    Hello folks,

    I've got a little issue with my custom StyledItemDelegate. I have got a list view where I want to add a remove button on the first column. This works pretty good but it is just visible in edit mode, but I want to have it visible when I hover the row.

    Can anyone give me a hint how to implement this?

    buttondelegate.h
    Qt Code:
    1. #ifndef BUTTONDELEGATE_H_
    2. #define BUTTONDELEGATE_H_
    3.  
    4. #include <QStyledItemDelegate>
    5.  
    6. class ButtonDelegate : public QStyledItemDelegate
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. ButtonDelegate(QObject *aParent);
    12.  
    13. QWidget *createEditor(
    14. QWidget *aParent,
    15. const QStyleOptionViewItem &aOption,
    16. const QModelIndex &aIndex) const;
    17.  
    18. virtual void setEditorData(
    19. QWidget *aEditor,
    20. const QModelIndex &aIndex) const;
    21.  
    22. virtual void setModelData(
    23. QWidget *aEditor,
    24. const QModelIndex &aIndex) const;
    25.  
    26. virtual void updateEditorGeometry(
    27. QWidget *aEditor,
    28. const QStyleOptionViewItem &aOption,
    29. const QModelIndex &aIndex) const;
    30.  
    31. };
    32.  
    33. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "buttondelegate.h"
    2.  
    3. #include <QToolButton>
    4. #include <QApplication>
    5.  
    6. //-----------------------------------------------------------------------------
    7. ButtonDelegate::ButtonDelegate(QObject *aParent)
    8. : QStyledItemDelegate(aParent)
    9. {
    10. }
    11.  
    12. //-----------------------------------------------------------------------------
    13. QWidget *ButtonDelegate::createEditor(
    14. QWidget *aParent,
    15. const QStyleOptionViewItem & /*aOption*/,
    16. const QModelIndex &aIndex) const
    17. {
    18. if (aIndex.column() == 0) {
    19. QToolButton *btn = new QToolButton(aParent);
    20. btn->setText("...");
    21. //btn->setAutoRaise(true);
    22. btn->setCheckable(true);
    23. btn->setFixedSize(QSize(16, 16));
    24.  
    25. return btn;
    26. }
    27.  
    28. return NULL;
    29. }
    30.  
    31. //-----------------------------------------------------------------------------
    32. void ButtonDelegate::setEditorData(
    33. QWidget * /*aEditor */,
    34. const QModelIndex & /*aIndex*/) const
    35. {
    36. }
    37.  
    38. //-----------------------------------------------------------------------------
    39. void ButtonDelegate::setModelData(
    40. QWidget *aEditor,
    41. const QModelIndex &aIndex) const
    42. {
    43. //QApplication::processEvents();
    44. if (static_cast<QToolButton*>(aEditor)->isChecked())
    45. aModel->removeRow(aIndex.row());
    46. }
    47.  
    48. //-----------------------------------------------------------------------------
    49. void ButtonDelegate::updateEditorGeometry(
    50. QWidget *aEditor,
    51. const QStyleOptionViewItem &aOption,
    52. const QModelIndex & /*aIndex*/) const
    53. {
    54. aEditor->setGeometry(aOption.rect);
    55. }
    To copy to clipboard, switch view to plain text mode 

    And yes I have searched on the forum and found some things but they didn't help.

    Kind regards,
    Sven

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom QStyledItemDelegate (QToolButton) - hovering instead of edit

    You can throw away your implementation because it's wrong and search the forum again. This question has already been answered lots of times. So far you made an editor for your item.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QStyledItemDelegate with custom QWidget editor
    By stefanadelbert in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2010, 00:19
  2. hovering problem in QGraphicsItem
    By wagmare in forum Qt Programming
    Replies: 4
    Last Post: 13th March 2009, 18:31
  3. update custom QStyledItemDelegate after drag
    By dano in forum Qt Programming
    Replies: 1
    Last Post: 17th November 2008, 19:29
  4. QWhatsThis appear when hovering over QPushButton?
    By seanmu13 in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2007, 21:06
  5. Replies: 4
    Last Post: 24th March 2006, 23:50

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.