Vash5556
16th May 2009, 02:14
I am trying to implement finding text in a TextEdit. I have written my own dialog to do this, and i got it to return the right string. Whenever i call find on the QTextEdit it never finds what im looking for. Here is my code for the find.
void VashTextEditor::find()
{
FindDialog findDialog(this);
if (!findDialog.exec())
return;
const QString searchString = findDialog.getSearchString();
bool test = documentEdit->find(searchString);
if (test)
{
QMessageBox::information(this, tr("Vash Text Editor"), tr("Expression found."));
}
else
{
QMessageBox::information(this, tr("Vash Text Editor"), tr("Expression not found."));
}
}
Here is the code for my FindDialog
#include <QtGui>
#include "finddialog.h"
FindDialog::FindDialog(QWidget *parent)
: QDialog(parent)
{
setupUi(this);
findButton->setEnabled(false);
connect(findButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
connect(findLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(toggleFindButton()));
}
QString FindDialog::getSearchString()
{
return findLineEdit->text();
}
void FindDialog::toggleFindButton()
{
QString currentText = findLineEdit->text();
if (!currentText.isEmpty())
{
findButton->setEnabled(true);
}
else
{
findButton->setEnabled(false);
}
}
Maybe im missing something simple. Any help would be appreciated. And if more code is needed feel free to ask and I will gladly post it for you.
void VashTextEditor::find()
{
FindDialog findDialog(this);
if (!findDialog.exec())
return;
const QString searchString = findDialog.getSearchString();
bool test = documentEdit->find(searchString);
if (test)
{
QMessageBox::information(this, tr("Vash Text Editor"), tr("Expression found."));
}
else
{
QMessageBox::information(this, tr("Vash Text Editor"), tr("Expression not found."));
}
}
Here is the code for my FindDialog
#include <QtGui>
#include "finddialog.h"
FindDialog::FindDialog(QWidget *parent)
: QDialog(parent)
{
setupUi(this);
findButton->setEnabled(false);
connect(findButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
connect(findLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(toggleFindButton()));
}
QString FindDialog::getSearchString()
{
return findLineEdit->text();
}
void FindDialog::toggleFindButton()
{
QString currentText = findLineEdit->text();
if (!currentText.isEmpty())
{
findButton->setEnabled(true);
}
else
{
findButton->setEnabled(false);
}
}
Maybe im missing something simple. Any help would be appreciated. And if more code is needed feel free to ask and I will gladly post it for you.