Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

QTextEdit as html templating engine

$
0
0
Hello. First – sorry for my English, hope you will understand me :) I need to implement a simple templating engine based on QTextEdit. It must work like this: Step 1) Load template into QTextEdit Step 2) Find every macros (like “{text}”), replace all of them with some text containers (frames or text blocks or something else) Step 3) Use text containers from step 2 to quickly insert/modify text in areas where were macroses For step 2 I choose QTextFrame. So please take a look at the code:  // pTextEdit is pointer to my QTextEdit instance  QString sTemplate = "<table border='1'><tr><td>{text}</td></tr></table>";  pTextEdit->setHtml(sTemplate);  if (pTextEdit->find("{text}"))  {   QTextFrameFormat FrameMft;   FrameMft.setBackground( QBrush(Qt::yellow) );   FrameMft.setBorder(0.0);   FrameMft.setBorderStyle(QTextFrameFormat::BorderStyle_None);   FrameMft.setMargin(0);   FrameMft.setPadding(0);     auto Cursor = pTextEdit->textCursor();   Cursor.removeSelectedText();   auto* pFrame = Cursor.insertFrame( FrameMft );     auto FrameCursor = pFrame->firstCursorPosition();   FrameCursor.insertText("Hello QTextFrame");  } For some reason QTextEdit adds two empty lines around QTextFrame – one before and one after. Please help me to find a way to insert text frames without empty lines or suggest something to achieve my goal without text frames (and without external libraries). Qt version = 5.1

Viewing all articles
Browse latest Browse all 13965

Trending Articles