Hi All,
I have made a QTableView which has 200 rows and 4 columns, when the user press the enter Key it opens a new QDialog which has 4 QlineEdits and these QlineEdits values has to be displayed in QTableView. here is the code snippet for QDialog
tooladddialog.cpp
QString ToolAddDialog
::toolgetValues() {
toolnolineEdit->selectAll();
line.append( toolnolineEdit->text() );
line.append( " " );
diameterlineEdit->selectAll();
line.append( diameterlineEdit->text() );
line.append( " " );
lengthlineEdit->selectAll();
line.append( lengthlineEdit->text() );
line.append( " " );
unitslineEdit->selectAll();
line.append( unitslineEdit->text() );
return line;
}
QString ToolAddDialog::toolgetValues()
{
QString line;
toolnolineEdit->selectAll();
line.append( toolnolineEdit->text() );
line.append( " " );
diameterlineEdit->selectAll();
line.append( diameterlineEdit->text() );
line.append( " " );
lengthlineEdit->selectAll();
line.append( lengthlineEdit->text() );
line.append( " " );
unitslineEdit->selectAll();
line.append( unitslineEdit->text() );
return line;
}
To copy to clipboard, switch view to plain text mode
tooform.cpp
void ToolForm
::keyPressEvent( QKeyEvent *event
) {
qDebug( "Key Press Event" );
switch ( event->key() )
{
case Qt::Key_Return: //Mapped with Enter Key
add_tool();
break;
case Qt::Key_Escape: //Mapped with Cancel key
close();
break;
default:
}
}
void ToolForm::add_tool()
{
ToolAddDialog tooladddialog;
if( tooladddialog.exec())
{
QString str
= tooladddialog.
toolgetValues();
if (!tooltableView)
return;
// now values should be added to the QTableView
}
}
void ToolForm::keyPressEvent( QKeyEvent *event )
{
qDebug( "Key Press Event" );
switch ( event->key() )
{
case Qt::Key_Return: //Mapped with Enter Key
add_tool();
break;
case Qt::Key_Escape: //Mapped with Cancel key
close();
break;
default:
QWidget::keyPressEvent(event);
}
}
void ToolForm::add_tool()
{
ToolAddDialog tooladddialog;
if( tooladddialog.exec())
{
QString str = tooladddialog.toolgetValues();
QStringList fields = str.split(" ");
if (!tooltableView)
return;
// now values should be added to the QTableView
}
}
To copy to clipboard, switch view to plain text mode
How to resolve this issue. if any snippet would be advantage.
Bookmarks