views:

172

answers:

1

I need to have the ability to use superscripts asnd subscripts in a QLineEdit in Qt 4.6. I know how to do superscripts and subscripts in a QTextEdit as seen below but I can't figure out how to do them in QLineEdit because the class doesn't contain a mergeCurrentCharFormat() function like QTextEdit does. Please help. Thanks

void MainWindow::superscriptFormat()
{
   QTextCharFormat format;
   format.setVerticalAlignment(QTextCharFormat::AlignSuperScript);
   if(ui->txtEdit->hasFocus())
      ui->txtEdit->mergeCurrentCharFormat(format);
}
+1  A: 

QLineEdit wasn't really made for this type of thing, as it was designed for simple text entry. You have a few options, however. The simplest one is to do as Hostile Fork suggested and use a QTextEdit, and add a style override to not show the scroll bar (which I assume would remove the arrows). The more complex one would be to either inherit QLineEdit and do your own drawing, or to make your own widget completely that appears similar to the QLineEdits do.

Caleb Huitt - cjhuitt
Thanks! I had found the word wrap part but was looking for something about the scroll bars and didn't see anything. I just double checked and found it. Now it looks great! Thanks!
Aaron McKellar