Results 1 to 2 of 2

Thread: QAbstractTextDocumentLayout handler problem

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QAbstractTextDocumentLayout handler problem

    I draw a QTextDocument on QGraphicsItem to edit xhtml <div> layer

    on a separate QObject i handle all text like QTextControl i connect my timer from blink cursor and the doc
    Qt Code:
    1. d = new QTextDocument(this);
    2. _layout = _d->documentLayout();
    3. connect ....
    To copy to clipboard, switch view to plain text mode 
    by timer event on blink cursor i update only his rect,
    now i have trouble to handle QAbstractTextDocumentLayout

    cursor blink run , i can edit document , move its , and all other...
    only text Highlight by selection from cursor not run...

    On line 36 from this code i have a true selecection by text
    selectAll(); or word select i send the update request and his not draw :-( why,

    note C_cursor ist the original QTextCursor from selection...

    Qt Code:
    1. /* child from class TextLayer : public QObject, public QGraphicsItem */
    2.  
    3. void MountTextPrivate::paint_doc( QPainter * painter ,
    4. const QStyleOptionGraphicsItem *option ,
    5. QBrush BGpage ,
    6. const QRectF fulllayer ,
    7. bool alternate )
    8. {
    9.  
    10.  
    11. /* Layer Background draw! */
    12. painter->save();
    13. painter->setPen(Qt::NoPen);
    14. painter->setBrush(BGpage);
    15. painter->drawRect(fulllayer);
    16. painter->restore();
    17. /* rect from frame root QTextDocument*/
    18. QRectF doc_rect = boundingRect();
    19.  
    20. QColor BackHightlight("#a6ffc7");
    21. BackHightlight.setAlpha(140);
    22.  
    23. QAbstractTextDocumentLayout::PaintContext CTX;
    24. CTX.selections;
    25. if (doc_rect.isValid()) {
    26. painter->setClipRect(doc_rect, Qt::IntersectClip);
    27. CTX.clip = doc_rect;
    28. }
    29. CTX.palette.setColor(QPalette::Highlight,BackHightlight);
    30. CTX.palette.setColor(QPalette::HighlightedText,Qt::black);
    31. /* blink cursor from timer event ! */
    32. if (cursortime) {
    33. CTX.cursorPosition = cursor_position;
    34. }
    35.  
    36. if (C_cursor.hasSelection()) {
    37. QAbstractTextDocumentLayout::Selection Internal_selection;
    38. Internal_selection.cursor = C_cursor;
    39. CTX.selections.append(Internal_selection);
    40. }
    41. _layout->draw(painter,CTX);
    42. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QAbstractTextDocumentLayout handler problem

    I find its without QPalette QAbstractTextDocumentLayout its draw nothing
    Maybe its can not read default palette style...

    super now i having a thiny QGraphicsTextItem to build a extended layer editor
    if you like to play grab the initial running code on:
    svn co http://fop-miniscribus.googlecode.co...icsTextEditor/ GraphicsTextEditor

    here the solution to display blinking cursor and selected cursor text...

    Qt Code:
    1. if (edit_enable) {
    2. if (C_cursor.hasSelection()) {
    3. QAbstractTextDocumentLayout::Selection Internal_selection;
    4. Internal_selection.cursor = C_cursor;
    5. QPalette::ColorGroup cg = cursorIsFocusIndicator ? QPalette::Active : QPalette::Inactive;
    6. Internal_selection.format.setBackground(CTX.palette.brush(cg, QPalette::Highlight));
    7. Internal_selection.format.setForeground(CTX.palette.brush(cg, QPalette::HighlightedText));
    8. Internal_selection.format.setProperty(QTextFormat::FullWidthSelection, true);
    9. CTX.selections.append(Internal_selection);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. problem with paint and erase in frame
    By M.A.M in forum Qt Programming
    Replies: 9
    Last Post: 4th May 2008, 20:17
  2. problem with opengl, zooming, drawpixels, and origin
    By ntp in forum General Programming
    Replies: 0
    Last Post: 22nd February 2008, 21:48
  3. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  4. Replies: 1
    Last Post: 16th October 2007, 22:41
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.