qt - Remove/delete/replace selected text in QGraphicsTextItem -


i delete selected text inside qgraphicstextitem.

i have been searching classes uses - qtextcursor, qtextdocument... can't find remove text, except clear() function of qtextdocument removes everything...

how can remove selection ?

    qtextcursor _cursor = textcursor();     if(_cursor.hasselection())         ? 

alternatively (since need custom paste command), how can replace selection existing text or html ?

    qclipboard* _clipboard = qapplication::clipboard();     const qmimedata* _mimedata = _clipboard->mimedata();     if (_mimedata->hashtml())     {         qtextcursor _cursor = textcursor();         if(_cursor.hasselection())              ?         _cursor.inserthtml(_mimedata->html());     } 

is not working qtextcursor::removeselectedtext()?

in next example, have @ beginning text qgraphics text item 1, see, can qtextdocument , qtextcursor document , insert words.

after that, move cursor next word. finally, select word under cursor (text) , remove our qgraphicstextitem.

#include <qapplication> #include <qgraphicsscene> #include <qgraphicsview> #include <qgraphicstextitem> #include <qtextcursor> #include <qtextdocument>  int main(int argc, char *argv[]) {     qapplication a(argc, argv);      qgraphicsscene scene;     qgraphicsview view(&scene);      qgraphicstextitem* item_1  = new qgraphicstextitem("qgraphics text item 1");     item_1->settextinteractionflags(qt::texteditorinteraction);      qtextdocument* doc = item_1->document();      scene.additem(item_1);      qtextcursor cursor(doc);     cursor.begineditblock();     cursor.inserttext(" hello ");     cursor.inserttext(" world ");     cursor.endeditblock();     cursor.moveposition(qtextcursor::nextword);     cursor.select(qtextcursor::wordundercursor);     cursor.removeselectedtext();      view.setfixedsize(640, 480);     view.show();     return a.exec(); } 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -