Results 1 to 3 of 3

Thread: How to edit the text in the QListWidget on the run time, by "SINGLE" clicking them?

  1. #1
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default How to edit the text in the QListWidget on the run time, by "SINGLE" clicking them?

    Qt Code:
    1. class genericTaskList : public QListWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. unsigned int rowCounter;
    6.  
    7. genericTaskList (QWidget *parentWidget)
    8. {
    9. setParent (parentWidget);
    10. setFixedSize (445, 445);
    11.  
    12. QListWidgetItem *defaultText = new QListWidgetItem ("Double click here to compose the new task.");
    13. defaultText->setFlags (defaultText->flags () | Qt :: ItemIsEditable);
    14.  
    15. rowCounter = 0;
    16. insertItem (rowCounter, defaultText);
    17.  
    18. QObject :: connect (this, SIGNAL (itemDoubleClicked (QListWidgetItem*)), this, SLOT (addDefaultText (QListWidgetItem*)));
    19. QObject :: connect (this, SIGNAL (itemChanged (QListWidgetItem*)), this, SLOT (addDefaultText (QListWidgetItem*)));
    20. }
    21.  
    22. public slots:
    23. void addDefaultText (QListWidgetItem*f)
    24. {
    25. // Returns the current row number.
    26. unsigned int currentRow = row (f);
    27. // Returns the current row text.
    28. QString textOfCurrentRow = f->text ();
    29.  
    30. // The new default row should get inserted if and only if, the last row created has been double clicked and its default text has been changed.
    31. if ((currentRow == rowCounter)
    32. && (textOfCurrentRow.toStdString () != "Double click here to compose the new task.")
    33. && (textOfCurrentRow.toStdString () != ""))
    34. {
    35. ++rowCounter;
    36.  
    37. QListWidgetItem *defaultText = new QListWidgetItem ("Double click here to compose the new task.");
    38. defaultText->setFlags (defaultText->flags () | Qt :: ItemIsEditable);
    39.  
    40. insertItem (rowCounter, defaultText);
    41. setCurrentRow (rowCounter);
    42. }
    43. else if (textOfCurrentRow.toStdString () == "")
    44. {
    45. takeItem (rowCounter);
    46.  
    47. QListWidgetItem *defaultText = new QListWidgetItem ("Double click here to compose the new task.");
    48. defaultText->setFlags (defaultText->flags () | Qt :: ItemIsEditable);
    49. insertItem (rowCounter, defaultText);
    50. setCurrentRow (rowCounter);
    51. }
    52. }
    53. };
    To copy to clipboard, switch view to plain text mode 

    The problem here is that I can edit the text if and only if I double click the text. Single click or anything else doesn't work. I tried changing that signal from double click to single click, didn't help.

    Please guide - Double clicking all the time is a pain.

  2. #2
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: How to edit the text in the QListWidget on the run time, by "SINGLE" clicking the

    Take a look at setEditTriggers(EditTriggers triggers) method

    EditTriggers could be one of the following values:
    Qt Code:
    1. QAbstractItemView::NoEditTriggers 0 No editing possible.
    2. QAbstractItemView::CurrentChanged 1 Editing start whenever current item changes.
    3. QAbstractItemView::DoubleClicked 2 Editing starts when an item is double clicked.
    4. QAbstractItemView::SelectedClicked 4 Editing starts when clicking on an already selected item.
    5. QAbstractItemView::EditKeyPressed 8 Editing starts when the platform edit key has been pressed over an item.
    6. QAbstractItemView::AnyKeyPressed 16 Editing starts when any key is pressed over an item.
    7. QAbstractItemView::AllEditTriggers 31 Editing starts for all above actions.
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: How to edit the text in the QListWidget on the run time, by "SINGLE" clicking the

    I'll try that and get back soon, thanks.

Similar Threads

  1. How to add the text items directly to the QListWidget on the "run time"?
    By TheIndependentAquarius in forum Qt Programming
    Replies: 4
    Last Post: 23rd February 2012, 09:28
  2. Replies: 3
    Last Post: 8th December 2011, 20:21
  3. Line Edit "hint" text
    By MTK358 in forum Newbie
    Replies: 1
    Last Post: 20th September 2010, 13:01
  4. Replies: 3
    Last Post: 26th August 2010, 09:57
  5. Replies: 4
    Last Post: 5th March 2010, 19:03

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.