Results 1 to 8 of 8

Thread: Remove selected QListWidgetItem

  1. #1
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Remove selected QListWidgetItem

    Hi, someone knows why I cant remove the selected item?

    Qt Code:
    1. void NuevoDestinatario::on_pushButtonEliminarTelefono_clicked(){
    2. if(Telefonos()->currentRow()!=-1){
    3. if(QMessageBox::question(this,"","Desea eliminar el elemento seleccionado",
    4. QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes){
    5. delete Telefonos()->takeItem(Telefonos()->currentRow());
    6. }
    7. }
    8. else QMessageBox::information(this,"","No hay elementos seleccionados");
    9. }
    To copy to clipboard, switch view to plain text mode 

    Always currentRow() is -1. And Telefonos() returns QListWidget*

    Thanks in advance

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Remove selected QListWidgetItem

    There's a difference between "selected item" and "current item". See this post.
    J-P Nurmi

  3. #3
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Remove selected QListWidgetItem

    But

    Qt Code:
    1. QMessageBox::information(this, "", QString::number(Telefonos()->selectedItems().count()));
    To copy to clipboard, switch view to plain text mode 

    always returns 0 (with item selected)

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Remove selected QListWidgetItem

    Works fine for me with both Qt 4.1.4 and 4.2.0-rc1.
    Attached Files Attached Files
    J-P Nurmi

  5. #5
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Remove selected QListWidgetItem

    Your sample runs perfectly, and I rewrite my function to this
    Qt Code:
    1. void NuevoDestinatario::EliminarTelefono_clicked(){
    2. qDeleteAll(Telefonos()->selectedItems());
    3. //QMessageBox::information(this, "", QString::number(Telefonos()->selectedItems().count()));
    4. //if(Telefonos()->currentRow()!=-1){
    5. //if(QMessageBox::question(this,"","Desea eliminar el elemento seleccionado",
    6. //QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes){
    7. //delete Telefonos()->takeItem(Telefonos()->currentRow());
    8. //}
    9. //}
    10. //else QMessageBox::information(this,"","No hay elementos seleccionados");
    11. }
    To copy to clipboard, switch view to plain text mode 

    and same behaviour, when I click the button the selected item is deselected and nothing is deleted

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Remove selected QListWidgetItem

    Have you any custom code which could cause the deselection of the selected items? Are you overriding or filtering any events?
    J-P Nurmi

  7. #7
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Remove selected QListWidgetItem

    Quote Originally Posted by jpn View Post
    Have you any custom code which could cause the deselection of the selected items? Are you overriding or filtering any events?
    Nope, only 4 buttons connected to functions to interact with the listWidget.

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Remove selected QListWidgetItem

    Heh, weird.. Have you adjusted list widget's selection mode or selection behaviour? Do the items really remain as selected in the GUI when you press the button?
    J-P Nurmi

Similar Threads

  1. Check Box problem
    By Seema Rao in forum Qt Programming
    Replies: 6
    Last Post: 30th November 2007, 19:32
  2. Removing the selected row in a QTreeView
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 29th May 2006, 11:21
  3. Zooming a paricular selected region
    By Kapil in forum Newbie
    Replies: 8
    Last Post: 9th May 2006, 14:41
  4. Problems subclassing QListWidgetItem
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 8th May 2006, 09:27
  5. QSettings again ... how to remove array elements
    By Mike in forum Qt Programming
    Replies: 4
    Last Post: 11th January 2006, 08:58

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.