August 31, 2011

M_31 M_31
Lab Rat
98 posts

Problem in QListWidget item’s renaming after executing a message box…

 

i have to set my QListWidget item’s as editable like..

  1. // this slot will execute when i press 'edit' from context menu  Edit option
  2. void testDlg::editList()
  3. {
  4.  QListWidgetItem *item = ui->listWidget->currentItem();
  5.     item->setFlags( item->flags() | Qt::ItemIsEditable );
  6.  
  7.     ui->listWidget->editItem( item );
  8. }

after editing the item , i will do a check , if the item is already present or not
If YES then i will throw a message like

  1.                QMessageBox msg;
  2.                 msg.setText(QString("Name already exists in this group!!"));
  3.                 msg.exec();
  4.                 emit editgroup(); // the corresponding SLOT is editlist()

After this message , my focus is still in edited item, but its not showing the corresponding item as editable..

2 replies

August 31, 2011

octal octal
Lab Rat
74 posts

I’m not sure to understand what’s your issue (maybe someone else will !).

So, could you explain a little bit more and post a more complete snippet of code ?

August 31, 2011

M_31 M_31
Lab Rat
98 posts

I have QListWidget with 4 items inside.

e.g., group1 group2 group3 group4

I can edit these items by pressing F2 button from the keyboard by placing the cursor on anyone of these items

let say , if i try to change the 4th item from “group4” to “group1”.
My application will throw some error like

“Name ‘group1’ already exist in this list”

  1. //i am getting the message  using the following code
  2. msg.setText(QString("Name").append(strName).append(" already exists in this list"));
  3. msg.exec();
  4. emit editgroup(); // the corresponding SLOT is editlist()

after throwing this error message , i want to have the same item as editable as i had before ..like when i press the F2 button from the keyboard….BUT ITS NOT OCCURING:-(
Even i am calling the SLOT editlist from the SIGNAL editgroup() ..after getting this messagebox
  1. connect( this, SIGNAL(editgroup()), this SLOT(editlist());

  1. // this is the slot function.
  2. void testDlg::editList()
  3. {
  4. QListWidgetItem *item = ui->listWidget->currentItem();
  5.    item->setFlags( item->flags() | Qt::ItemIsEditable );    
  6.  ui->listWidget->editItem( item );
  7. }

 
  ‹‹ The Dangers of Copy On Write (COW)      Unique blocking connection or somethig like it needed ››

You must log in to post a reply. Not a member yet? Register here!