Russian Qt Forum

Qt => Вопросы новичков => Тема начата: sektor от Март 30, 2018, 11:10



Название: QPainter в QTextDocument
Отправлено: sektor от Март 30, 2018, 11:10
Как сделать так, чтобы QPainter рисовал в QTextDocument при этом чтобы текст, который там был не удалился?

Код:
Printer::Printer(QWidget *pwgt):QWidget(pwgt)
{
    m_pprinter = new QPrinter(QPrinter::HighResolution);

    textDocument = new QTextDocument;


    barcode = new EAN13(this);
    barcodeStr = "4650000000" ;
}

Printer::~Printer()
{
    delete m_pprinter;

    delete textDocument;
}

void Printer::slotPrint(QString data)
{
    m_pprinter->setPrinterName("Xprinter XP-360B");
    m_pprinter->setPageMargins(4,4,4,4, QPrinter::Millimeter);

    data.replace("12pt", "17pt");
    textDocument->setHtml(data);
    textDocument->setPageSize(m_pprinter->pageRect().size());

    QPrintPreviewDialog dialog(m_pprinter, this);
    connect(&dialog, SIGNAL(paintRequested(QPrinter*)), SLOT(slotPrint(QPrinter*)));
    dialog.exec();

}


void Printer::slotPrint(QPrinter *printer)
{
    //
    draw(printer);
    //textDocument->print(printer);
}

void Printer::draw(QPaintDevice *ppd)
{
    int Wd, Ht ;


    Wd = m_pprinter->width() ;
    Ht = m_pprinter->height() ;

    QPainter painter(ppd) ;


    barcode->makePattern(barcodeStr);

    qreal scale = painter.device()->logicalDpiX()/25.4;
    barcode->draw(QRectF(360, Ht-70, 29.83 * scale, 8.74* scale), painter) ;

    painter.end();

    textDocument->drawContents(&painter);
}




Название: Re: QPainter в QTextDocument
Отправлено: sektor от Апрель 02, 2018, 08:54
Код:
void Printer::slotPrint(QPrinter *printer)
{
    //
    draw(printer);
    //textDocument->print(printer);
}

void Printer::draw(QPaintDevice *ppd)
{
    int Wd, Ht ;


    Wd = m_pprinter->width() ;
    Ht = m_pprinter->height() ;

    QPainter painter(ppd) ;


    barcode->makePattern(barcodeStr);

    qreal scale = painter.device()->logicalDpiX()/25.4;
    barcode->draw(QRectF(360, Ht-70, 29.83 * scale, 8.74* scale), painter) ;
   
   textDocument->drawContents(&painter);

    painter.end();

   }

Как такое не смог видеть, ай ай ай!!! Здесь есть кто ни будь? Что-то форум пустует.


Название: Re: QPainter в QTextDocument
Отправлено: gil9red от Апрель 02, 2018, 21:48
Есть