Results 1 to 3 of 3

Thread: Remove row button in QTabelview

  1. #1
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Remove row button in QTabelview

    Hello all!

    I am having some problems with a QPushButton used inside a QTableview. This button needs to remove the row but when I remove one row its changes the index and the button starts to remove the wrong row.

    How can I pass the right parameter to void "MainWindow:n_excluir_clicked(int linha)" ?

    Thanks a lot.

    Code below:
    Qt Code:
    1. void MainWindow::adicionarLinha(QStandardItemModel *modelo, QTableView *tabela)
    2. {
    3. spinBoxDelegar = new spinBoxDelegate(this);
    4.  
    5. QPushButton *excluirButton = new QPushButton(*iconeExcluirButton, "", 0);
    6. excluirButton = new QPushButton(*iconeExcluirButton, "", 0);
    7. excluirButton->setStyleSheet("background-color: rgb(255, 255, 255); color: rgb(255, 255, 255); border: 0");
    8. QSignalMapper *mapearSinalBotaoExcluir = new QSignalMapper(this);
    9.  
    10. modelo->insertRow(modelo->rowCount());
    11. modelo->setData(modelo->index(modelo->rowCount()-1,1), 1);
    12. tabela->setItemDelegateForColumn(1, spinBoxDelegar);
    13. tabela->setIndexWidget(modelo->index(modelo->rowCount()-1,2), excluirButton);
    14. tabela->edit(modelo->index(modelo->rowCount()-1,0));
    15.  
    16. mapearSinalBotaoExcluir->setMapping(excluirButton, modelo->rowCount()-1);
    17. connect(excluirButton, SIGNAL(clicked()), mapearSinalBotaoExcluir, SLOT(map()));
    18. connect(mapearSinalBotaoExcluir, SIGNAL(mapped(int)), this, SLOT(on_excluir_clicked(int)));
    19. }
    20.  
    21. void MainWindow::on_excluir_clicked(int linha)
    22. {
    23. this->modelo1->removeRow(linha);
    24. }
    To copy to clipboard, switch view to plain text mode 
    Captura de Tela 2014-03-01 às 09.55.39.jpg

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Remove row button in QTabelview

    One thing you can try is to have one signal mapper and store all button mappings in there.

    Then, when you remove a row, you iterate over the mapping numbers, retrieve the sender object, remove the mapping for that object and create a new mapping with the row the button is now in.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Remove row button in QTabelview

    Could you help me with some code?

    Thanks

Similar Threads

  1. Remove max,min button on a QMainWindow
    By Krish_ng in forum Qt Programming
    Replies: 9
    Last Post: 3rd August 2012, 13:36
  2. Replies: 2
    Last Post: 26th April 2011, 11:44
  3. Special delegate for QTabelView
    By kunashir in forum Qt-based Software
    Replies: 0
    Last Post: 17th March 2011, 13:22
  4. how to remove tab with closable button.
    By ishkabible in forum Newbie
    Replies: 8
    Last Post: 20th September 2010, 02:03
  5. Remove restore button
    By vermarajeev in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2007, 13:29

Tags for this Thread

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.