I have the following problem, I have a QTableWidget to which I have added some QDoubleSpinBox to some cells, all good so far my question is how I can do to select all the content of the spinbox when changing the focus, I mean when pressing the key tab and when they receive the focus, I will appreciate any suggestions.
I leave my code:
void MainClass::setData(double val1, double val2,int _rowCount)
{
for (int i=0;i<= _rowCount; i++) {
int rowCount=ui->tableWidget_4->rowCount();
// ui->tableWidget_4->setRowCount(rowCount);
//primera columna
ui->tableWidget_4->insertRow(rowCount);
// qDebug()<<rowCount;
QTableWidgetItem *item=new QTableWidgetItem(QString("v %1").arg(v));
ui->tableWidget_4->setItem(rowCount,V,item);
//segunda columna columna
// ui->tableWidget_4->insertRow(rowCount);
QTableWidgetItem *item1=new QTableWidgetItem(0);
ui->tableWidget_4->setItem(rowCount,Velocidad,item1);
ui->tableWidget_4->setCellWidget(rowCount,Velocidad,new QDoubleSpinBox);
QDoubleSpinBox *sb=qobject_cast<QDoubleSpinBox *>(
ui->tableWidget_4->cellWidget(rowCount,Velocidad));
sb->setValue(val1);
// qDebug()<<item1->data(Qt::DisplayRole).toString();
//tercera columna columna
// ui->tableWidget_4->insertRow(rowCount);
QTableWidgetItem *item2=new QTableWidgetItem(QString("h %1").arg(h));
ui->tableWidget_4->setItem(rowCount,H,item2);
//cuarta columna columna
// ui->tableWidget_4->insertRow(rowCount);
QTableWidgetItem *item3=new QTableWidgetItem(val2);
ui->tableWidget_4->setItem(rowCount,Profundidad,item3);
ui->tableWidget_4->setCellWidget(rowCount,Profundidad,new QDoubleSpinBox);
QDoubleSpinBox *sb2=qobject_cast<QDoubleSpinBox *>(
ui->tableWidget_4->cellWidget(rowCount,Profundidad));
sb2->setValue(val2);
v++;
h++;
}
here the form
Note that when the spinboxes are in focus, only the cursor blinks but not all the content is selected.
note: in the assignment of the column number in setItem I use an enumeration instead of the column numbers.
enum ColNames{V,Velocidad,H,Profundidad};

One possible solution is to override the focusInEvent method of the QDoubleSpinBox that is invoked when it receives the focus, and then select all the text.
And then set it using the setCellWidget method.
You can also avoid using the setCellWidget method and use the delegate: