Answer the question
In order to leave comments, you need to log in
How to write a universal function from repeated methods?
There is a large form with many fields, for each field I write the following code:
bool case_medical_care::eventFilter(QObject *target, QEvent *event)
{
//ПОЛЕ 1
if (target == ui->data)
{
if (event->type() == QEvent::FocusIn and dataFocus)
{
dataFocus = false;
on_data_textEdited(ui-data->text());
}
if (event->type() == QEvent::FocusOut and !dataFocus)
{
dataFocus = true;
ui->data->setCursorPosition(0);
}
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() == Qt::Key_Down or keyEvent->key() == Qt::Key_Up)
{
on_dataP_textEdited(ui->data->text());
}
}
}
//ПОЛЕ 2
if (target == ui->text)
{
if (event->type() == QEvent::FocusIn and textFocus)
{
textFocus = false;
on_text_textEdited(ui-text->text());
}
if (event->type() == QEvent::FocusOut and !textFocus)
{
textFocus = true;
ui->text->setCursorPosition(0);
}
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() == Qt::Key_Down or keyEvent->key() == Qt::Key_Up)
{
on_text_textEdited(ui->text->text());
}
}
}
return QObject::eventFilter(target, event);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question