Results 1 to 4 of 4

Thread: Displaying a QPushButton in a QTableView

  1. #1

    Default Displaying a QPushButton in a QTableView

    Hi,

    I want to display a QPushButton next to a row in a QSqlTableModel. The approach I have taken is using the setIndexWidget method and mapping the Button to the row with a QSignalMapper:

    Qt Code:
    1. int column = model->columnCount();
    2. model->insertColumn(column);
    3. QSignalMapper *sigMap = new QSignalMapper(this);
    4. QPushButton *button;
    5. for(int i = 0; i < model->rowCount(); i++) {
    6. button = new QPushButton(ui->tblViewClient);
    7. button->setText("Show Details");
    8. connect(button, SIGNAL(clicked()), sigMap, SLOT(map()));
    9. sigMap->setMapping(button, model->data(model->index(i,0)).toInt());
    10. ui->tblViewClient->setIndexWidget(model->index(i,column), button);
    11. }
    12. connect(sigMap, SIGNAL(mapped(int)), this, SLOT(showDetails(int)));
    To copy to clipboard, switch view to plain text mode 

    This works fine for me. But... On double clicking a row I am displaying the models data with a QDataWidgetMapper. If I close this dialog the model emits a dataChanged signal, the tableView gets rerendered and my buttons get lost (because I am using a QSqlTableModel...).

    My question is, can you think of a simple way to avoid this? Connecting to dataChanged and repainting the whole thing does not help.

    I hope my first post here is not too weird. :-)

    Kind regards,
    Philipp.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Displaying a QPushButton in a QTableView

    Please search the forum. This has been discussed here many times.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3

    Default Re: Displaying a QPushButton in a QTableView

    So a solution would be to write a Delegate for the Button, like discussed in this post and subclass my QSqlTableModel to add an extra column for the Button?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Displaying a QPushButton in a QTableView

    That's one of the possibilities.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Add QPushButton to cell in QTableView?
    By nikhil in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2010, 09:01
  2. QTableView, QTextEdit and QPushButton
    By hml in forum Newbie
    Replies: 0
    Last Post: 5th March 2010, 14:22
  3. Problems with QPushButton displaying an icon
    By John82 in forum Qt Programming
    Replies: 9
    Last Post: 2nd July 2009, 17:42
  4. QTableView row-displaying problem
    By MasterBLB in forum Qt Programming
    Replies: 0
    Last Post: 21st June 2009, 11:10
  5. Dragging an item from QTableView to a QPushButton
    By steg90 in forum Qt Programming
    Replies: 2
    Last Post: 23rd May 2007, 11:57

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
  •  
Qt is a trademark of The Qt Company.