Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. select all content upon receiving focus

select all content upon receiving focus

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 373 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • lincolnL Offline
    lincolnL Offline
    lincoln
    wrote on last edited by lincoln
    #1

    hello guys, 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 can I do to select all the content of the spinbox when changing the focus, I mean when pressing the tab key and when they receive the focus, and also when it is clicked inside the control. I would 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

    ea0865dc-eeaf-4694-b41f-16dfe29e05b3-image.png

    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};
    

    Solitary wolf

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved