c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -


i registred handler simple qtextobjectinterface, draws 10x10 red rectangle. when used qtextedit in normal qwidget app, worked.
when used qquicktextedit (textedit qml component) in qt quick app, doesn't worked (nothing drawed, rectangle in textedit reserved, because when change cursor position, notice there something, empty space, nothing drawed.
qtextobjectinterface intrinsicsize method called (that explains why see there empty space 10x10), drawobject method isn't.

i did research , found problem here:

qquicktextedit.cpp qt 5.3.0 sources (line 1821)

qsgnode *qquicktextedit::updatepaintnode(qsgnode *oldnode, updatepaintnodedata *updatepaintnodedata) { . . . if (textframe->firstposition() > textframe->lastposition()                     && textframe->frameformat().position() != qtextframeformat::inflow) {                 updatenodetransform(node, d->document->documentlayout()->frameboundingrect(textframe).topleft());                 const int pos = textframe->firstposition() - 1;                 protectedlayoutaccessor *a = static_cast<protectedlayoutaccessor *>(d->document->documentlayout());                 qtextcharformat format = a->formataccessor(pos);                 qtextblock block = textframe->firstcursorposition().block();                 node->m_engine->setcurrentline(block.layout()->linefortextposition(pos - block.position()));                 node->m_engine->addtextobject(qpointf(0, 0), format, qquicktextnodeengine::unselected, d->document,                                               pos, textframe->frameformat().position());                 nodestart = pos;             } 

it never reaches point node->m_engine->addtextobject called.
because part of if condition textframe->firstposition() > textframe->lastposition() evaluated false.
tried std::cout firstpostion , lastposition when established context , firstposition 0, lastposition 1.

#include <qapplication> #include <qqmlapplicationengine> #include <qqmlcontext> #include <qtextdocument> #include <qquicktextdocument> #include <iostream> #include <qtextcursor> #include <qtextblock> #include <qpainter> #include <qabstracttextdocumentlayout> #include <qtextcharformat> #include "qmlcomponentspace.h" #include <qtextedit>  int main(int argc, char *argv[]) {     qapplication app(argc, argv);      qqmlapplicationengine engine;     engine.load(qurl(qstringliteral("qrc:/main.qml")));      qtextdocument * doc = engine.rootobjects().first()->findchild<qobject *>("editor")->property("textdocument").value<qquicktextdocument *>()->textdocument();      qtextcursor cur(doc);      int objecttype = qtextformat::userobject + 1000;      qmlcomponentspace * component = new qmlcomponentspace();      doc->documentlayout()->registerhandler(objecttype, component);      qtextcharformat fmt;     fmt.setobjecttype(objecttype);     fmt.setforeground(qt::red);     fmt.setbackground(qt::red);      cur.moveposition(qtextcursor::end);      cur.inserttext(qstring(qchar::objectreplacementcharacter), fmt);      std::cout << "first:" << doc->rootframe()->firstposition() << std::endl;     std::cout << "end:" << doc->rootframe()->lastposition() << std::endl;      return app.exec(); } 

what missing?


Comments

Popular posts from this blog

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -