mainwindow:

ui->tableView->setItemDelegateForColumn(model->fieldIndex("attach"), new buttonDelegate(ui->tableView)); //кнопка в таблице делегат 

further delegate buttondelegate.cpp

 bool buttonDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) { if( event->type() == QEvent::MouseButtonRelease ) { QMouseEvent * e = (QMouseEvent *)event; int clickX = e->x(); int clickY = e->y(); QRect r = option.rect; int x,y,w,h; x = r.left() + r.width() - 30; y = r.top(); w = 30;//ширина кнопки h = 30;//высота кнопки //если попали в кнопку if( clickX > x && clickX < x + w ) if( clickY > y && clickY < y + h ) { int row = index.row(); emit createNewUpload(row); } } } 

by pressing the delegate a window should open

 void MainWindow::uploadFile(int row) { uploadFile_window = new uploadFileForm(); uploadFile_window->orderinfo(row); uploadFile_window->show(); } 

and so on

QUESTION how to make connect when clicking on a delegate button. After all, it has not yet been created before clicking. Well, if it is not at all on the "guest" as correct.

 connect(что тут писать?,SIGNAL(createNewUpload(int row)),this,SLOT(uploadFile(int row))); 

    1 answer 1

    First create a delegate, then connect the signal, like this:

     buttonDelegate *delegate = new buttonDelegate(ui->tableView); connect(delegate, SIGNAL(createNewUpload(int row)), this, SLOT(uploadFile(int row))); ui->tableView->setItemDelegateForColumn(model->fieldIndex("attach"), delegate); 
    • THANKS helped). - Alexey Smirnov