-2
我有計劃:如何通過ctrl + V從剪貼板插入html到QTextEdit?
int main(int argc, char *argv[]){
QApplication app(argc, argv);
QTextEdit te;
te.setHtml("<!DOCTYPE html>"
"<html>"
"<body style = \"background-color:powderblue;\">"
"<h1>My First Heading</h1>"
"<p>My first paragraph.</p>"
"</body>"
"</html>");
te.resize(500, 300);
te.show();
return app.exec();
}
這個程序創建如下窗口:
我有另一個程序:
int main(int argc, char *argv[]){
QApplication app(argc, argv);
QTextEdit te;
te.resize(500, 300);
te.show();
return app.exec();
}
但是,如果我複製文本
<!DOCTYPE html>
<html>
<body style="background-color:powderblue;">
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
通過按CTRL + V到由該程序創建的窗口剪貼板中,我看到:
我如何重寫我的程序來顯示HTML作爲第一個圖像?
就不好說了,如果你不顯示的代碼。當您鍵入文本而不是粘貼它時,行爲會有所不同嗎? – KjMag
閱讀http://doc.qt.io/qt-5/qclipboard.html – hyde
您可能還想閱讀http://doc.qt.io/qt-5/qtextedit.html#insertFromMimeData – hyde