Qt - 如何在 QLineEdit 中执行上标和下标?
我需要能够在 Qt 4.6 的 QLineEdit 中使用上标和下标。我知道如何在 QTextEdit 中执行上标和下标,如下所示,但我不知道如何在 QLineEdit 中执行上标和下标,因为该类不包含像 QTextEdit 那样的 mergeCurrentCharFormat() 函数。请帮忙。谢谢
void MainWindow::superscriptFormat()
{
QTextCharFormat format;
format.setVerticalAlignment(QTextCharFormat::AlignSuperScript);
if(ui->txtEdit->hasFocus())
ui->txtEdit->mergeCurrentCharFormat(format);
}
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
QLineEdit
并不是真正为此类事情而设计的,因为它是为简单的文本输入而设计的。不过,您有几个选择。最简单的方法是按照 Hostile Fork 的建议进行操作并使用 QTextEdit,并添加样式覆盖以不显示滚动条(我认为这会删除箭头)。更复杂的方法是继承 QLineEdit 并进行您自己的绘图,或者完全制作您自己的小部件,其外观与 QLineEdit 类似。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 aQTextEdit
, 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 inheritQLineEdit
and do your own drawing, or to make your own widget completely that appears similar to theQLineEdit
s do.