本文介绍了如何在qt中更改QTextDocument的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨所有
如何在qt中更改大小QTextDocument?
这是我的代码?
hi all
how change size QTextDocument in qt ?
this is my code ?
MainWindow::MainWindow(QString path)
{
QPalette* palette = new QPalette();
// palette->setBrush(QPalette::Background,*(new QBrush(*(new QPixmap(path+"/res/background.jpg")))));
setPalette(*palette);
setWindowTitle("Alzekr");
resize(1024,819);
//QLabel *qlabel=createLabel();
QTextDocument *textDocument=new QTextDocument;
QVBoxLayout *vbox=new QVBoxLayout;
//-------------------------------------------------------------------------------------
QTextEdit *editor = new QTextEdit;
QTextDocument *document = new QTextDocument(editor);
QTextCursor cursor(document);
QImage image(64, 64, QImage::Format_RGB32);
image.fill(qRgb(255, 160, 128));
//! [Adding a resource]
document->addResource(QTextDocument::ImageResource,
QUrl("mydata://image.png"), QVariant(image));
document->setPageSize(QSize(100,200));
//! [Adding a resource]
//! [Inserting an image with a cursor]
QTextImageFormat imageFormat;
imageFormat.setName("mydata://image.png");
cursor.insertImage(imageFormat);
//! [Inserting an image with a cursor]
cursor.insertBlock();
cursor.insertText("Code less. Create more.");
editor->document()->setPageSize( QSizeF( 100, 200 ) );
document->setTextWidth(200);
QSize size = document->size().toSize();
size.setWidth(200);
size.setHeight(200);
editor->setDocument(document);
//! [Inserting an image using HTML]
editor->append("<img src=\"mydata://image.png\" />");
//-------------------------------------------------------------------------------------
vbox->addWidget(editor);
setLayout(vbox);
}
但不是改变大小QTextDocument?
but not change size QTextDocument ?
推荐答案
QSizeF size(200, 200);
document->setPageSize(size);
这篇关于如何在qt中更改QTextDocument的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!