开发者

Qt - How to do superscripts and subscripts in a QLineEdit?

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->txtEdi开发者_StackOverflow中文版t->hasFocus())
      ui->txtEdit->mergeCurrentCharFormat(format);
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜