Results 1 to 6 of 6

Thread: Delegate is not validated automatically with my own widget

  1. #1
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Lightbulb Delegate is not validated automatically with my own widget

    Hi,

    In an editable QTableView, I added the following delegate:
    Qt Code:
    1. SKGQueryDelegate::SKGQueryDelegate(QObject* parent, SKGDocument* iDoc, bool iModeUpdate):
    2. QItemDelegate(parent), document(iDoc), updateMode(iModeUpdate)
    3. {
    4. }
    5.  
    6. SKGQueryDelegate::~SKGQueryDelegate()
    7. {
    8. document=NULL;
    9. }
    10.  
    11. QWidget* SKGQueryDelegate::createEditor(QWidget *parent,
    12. const QStyleOptionViewItem & option ,
    13. const QModelIndex & index ) const
    14. {
    15. SKGTRACEIN(1, "SKGQueryDelegate::createEditor");
    16.  
    17. QTableWidgetItem* it_h=((QTableWidget*) this->parent())->horizontalHeaderItem(index.column());
    18. QString attname=it_h->data(Qt::UserRole).toString();
    19.  
    20. SKGPredicatCreator* editor=new SKGPredicatCreator(parent, document, attname, updateMode);
    21.  
    22. return editor;
    23. }
    24.  
    25. void SKGQueryDelegate::setEditorData ( QWidget * editor, const QModelIndex & index ) const
    26. {
    27. SKGTRACEIN(1, "SKGQueryDelegate::setEditorData");
    28. SKGPredicatCreator *pred = dynamic_cast<SKGPredicatCreator*>(editor);
    29. if (pred) {
    30. pred->setXmlDescription(index.model()->data(index, Qt::UserRole).toString());
    31. } else QItemDelegate::setEditorData (editor, index);
    32. }
    33.  
    34. void SKGQueryDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
    35. const QModelIndex &index) const
    36. {
    37. SKGTRACEIN(1, "SKGQueryDelegate::setModelData");
    38. SKGPredicatCreator *pred = dynamic_cast<SKGPredicatCreator*>(editor);
    39. if (pred && model) {
    40. QString xml=pred->xmlDescription();
    41. model->setData(index, pred->text(), Qt::DisplayRole);
    42. model->setData(index, xml, Qt::UserRole);
    43. } else QItemDelegate::setModelData (editor, model, index);
    44. }
    To copy to clipboard, switch view to plain text mode 

    using my own widget SKGPredicatCreator:
    Qt Code:
    1. class SKGBANKGUI_EXPORT SKGPredicatCreator : public QWidget
    2. {
    3. Q_OBJECT
    4. Q_PROPERTY( QString test READ text USER true)
    5. Q_PROPERTY( QString xmlDescription READ xmlDescription WRITE setXmlDescription)
    6.  
    7. public:
    8. /**
    9.   * Default Constructor
    10.   * @param parent the parent
    11.   * @param document the document
    12.   * @param attribute name of the attribute
    13.   */
    14. explicit SKGPredicatCreator(QWidget *parent = 0, SKGDocument* document=NULL, const QString& attribute="", bool iSQL=false);
    15.  
    16. /**
    17.   * Default Destructor
    18.   */
    19. virtual ~SKGPredicatCreator();
    20.  
    21. /**
    22.   * Get text
    23.   * @return text
    24.   */
    25. virtual QString text();
    26.  
    27. /**
    28.   * Get Text from XML description
    29.   * @param iXML the description
    30.   */
    31. static QString getTextFromXml(const QString& iXML);
    32.  
    33. /**
    34.   * Get XML description
    35.   * @return description
    36.   */
    37. virtual QString xmlDescription();
    38.  
    39. /**
    40.   * Set XML description
    41.   * @param iText the description
    42.   */
    43. virtual void setXmlDescription(const QString& iXML);
    44. signals:
    45.  
    46.  
    47. public slots:
    48.  
    49.  
    50. private slots:
    51. void onOperatorChanged();
    52.  
    53. private:
    54. Q_DISABLE_COPY(SKGPredicatCreator);
    55. bool updateMode;
    56.  
    57. SKGComboBox* kOperator;
    58. QWidget* kValue1;
    59. QWidget* kValue2;
    60. };
    To copy to clipboard, switch view to plain text mode 

    It works fine, except for the following scenario:
    1-double click on a cell ==> cell becomes editable (SKGPredicatCreator is created).
    2-Enter values in custom widget SKGPredicatCreator (do not click enter)
    3-Click on external button "Add"

    Problem: Values entered in step 2 are not automatically validate when I do step 3 (focus on SKGPredicatCreator is lost).
    It's not the case, if I use a std widget like QComboBox.

    Why ? What I have to do to activate automatic validation ?

  2. #2
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Delegate is not validated automatically with my own widget

    No idea !

  3. #3
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Delegate is not validated automatically with my own widget

    Please. I didn't find the solution !

  4. #4
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Delegate is not validated automatically with my own widget

    Nobody knows !

  5. #5
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Delegate is not validated automatically with my own widget

    I'm not sure if I have understand your scenario.

    The "external" button is not part of the editor widget? Why not make the button part of the editor? Clicking on "add" would do a validation and close the widget if the data is valid? Afair "setModelData()" is called if the editor loses his focus.

    or ask a method like "isValid()" in "setModelData()" and only add the data to the model if it returns true.

  6. #6
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Delegate is not validated automatically with my own widget

    To be clearer:

    I have a QTreeWidget with a delegate for edition of cells.

    Case 1- If the component used for edition is a QComboBox, then the edition mode is closed and the value of the QComboBox is kept when the focus is lost.
    This is a standard behaviour with code needed.

    Case 2- If the component used for edition is a my widget (A frame containing 3 QComboBox), then the edition mode is closed and the value of the QComboBox is NOT kept (cell is empty) when the focus is lost.
    So, end user needs to validate the cell by clicking "Return".

    How to get same behaviour in Case 2 than in Case 1 ?

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. How to Open & Close a Widget ?!!
    By Fatla in forum Qt Programming
    Replies: 6
    Last Post: 13th June 2008, 20:39
  3. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  4. Replies: 1
    Last Post: 22nd October 2007, 02:04
  5. Creating advanced widget in a delegate.
    By bunjee in forum Qt Programming
    Replies: 8
    Last Post: 5th February 2007, 08:09

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.