Qt富文本编辑器 - 是否已经有一个?

时间:2012-07-24 12:14:36

标签: c++ qt qtextedit richtext rich-text-editor

我需要Qt的富文本编辑器。我一直在考虑使用QTextEdit,因为它是一个富文本编辑,但我需要两个在该小部件中不存在的东西:

  • 用户应该能够更改文本颜色,文本字体,下划线,粗体,斜体文本,所以我需要像文本编辑器工具栏这样的控件(我需要自己编写代码)吗? ?)

  • 用户应该可以通过搜索图像来拖动或添加。现在,如果我尝试将图像复制并粘贴到我的QTextEdit上,我只看到这个

enter image description here

我应该如何满足每一项需求?

4 个答案:

答案 0 :(得分:3)

1)看看这个官方示例,它应该为您提供一个能够使用工具栏更改文本的富文本编辑器:

http://doc.qt.io/qt-5/qtwidgets-richtext-textedit-textedit-cpp.html

要拖放图像,我担心你必须继承文本编辑(QTextEdit或QTextBrowser)并实现这两种方法:

Sub test_CairoCoder()
Dim wS As Worksheet, _
    LastRow As Long, _
    ColorChg As Boolean, _
    OrderNb As String

Set wS = ActiveSheet
ColorChg = False

With wS
    LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
    OrderNb = wS.Cells(2, 1)
    For i = 2 To LastRow
        If .Cells(i, 1) <> .Cells(i + 1, 1) And .Cells(i, 1) <> .Cells(i - 1, 1) Then
            ColorChg = Not ColorChg
            If ColorChg Then
                .Range(.Cells(i, "A"), .Cells(i + 1, "A")).Interior.Color = vbRed
            Else
                .Range(.Cells(i, "A"), .Cells(i + 1, "A")).Interior.Color = vbYellow
            End If
        Else
            If .Cells(i, 1) <> .Cells(i + 1, 1) Then
            Else
                If OrderNb <> .Cells(i, 1) Then
                    OrderNb = .Cells(i, 1)
                    ColorChg = Not ColorChg
                Else
                End If

                If ColorChg Then
                    .Range(.Cells(i, "A"), .Cells(i + 1, "A")).Interior.Color = vbRed
                Else
                    .Range(.Cells(i, "A"), .Cells(i + 1, "A")).Interior.Color = vbYellow
                End If
            End If
        End If
    Next i
End With
MsgBox "All done!", vbInformation + vbOKOnly

End Sub

2)这是一个GitHub项目,可以实现您所需要的一切,甚至更多:

https://github.com/Anchakor/MRichTextEditor

最后,如果您想了解富文本编辑器的工作原理,请参阅以下文档:

http://doc.qt.io/qt-5/richtext.html

答案 1 :(得分:1)

您可以使用从Deko CRM中提取的此编辑器: http://www.hobrasoft.cz/en/blog/bravenec/qt-rich-text-editor

答案 2 :(得分:0)

另一个想法可能是使用WebKit制作这个小部件。请参阅:http://blog.qt.digia.com/blog/2009/03/12/wysiwyg-html-editor/

请注意,此处链接的git存储库已移至此网址:https://qt.gitorious.org/qt-labs/graphics-dojo/source/8000ca3b229344ed2ba2ae81ed5ebaee86e9d63a

答案 3 :(得分:-1)

相关问题