[Qt-interest] problem with QTextCursor
Keshava Krishna
keshavkrishna88 at gmail.com
Tue Mar 3 08:06:12 CET 2009
hi,
'm building a text editor that uses a text cursor.
i use the following code to open a text doucument...
void open_text()
{
textfileName=QFileDialog::getOpenFileName(this,tr("Open
File"),"/home/keshava");
QFileInfo fi(textfileName);
QFile file(textfileName);
if (file.open(QIODevice::ReadWrite))
{
QString data(file.readAll());
if (textfileName.endsWith(".html"))
textEditor->setHtml(data);
else
textEditor->setPlainText(data);
}
document=textEditor->document();
textCursor = new QTextCursor(document);
textCursor->setPosition(0);
}
now i want to get the offset position of the cursor (after i change it by
using mouse) in a dialog, so i used the following code
void display_offset()
{
QDialog *offset_dialog =new QDialog();
QTextEdit *offset_text = new QTextEdit(offset_dialog);
int i=textCursor->position();//this returns the current position
QString *offset= new QString();
*offset=offset->setNum(i);
offset_text->setText(*offset); //set the position as text in the
dialog
offset_dialog->show();
}
but the dialog shows only 0, it does not show the changed position, if i set
the intia position as say 10 in opening function, it shows 10 itself...
is the cursor i see on the screen different(whose position can be changed
using mouse)??
can anyone help me out??
Regards,
Keshava.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090303/1880bd49/attachment.html
More information about the Qt-interest-old
mailing list