Click here to Skip to main content
15,886,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
}


but not change size QTextDocument ?
Posted

1 solution

You are just changing the size of the QSize object with what you have.

Try something like
QSizeF size(200, 200);
document->setPageSize(size);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900