Results 1 to 3 of 3

Thread: QPlainTextEdit inherited + invisibleQTextBlock + INVALID vertical scroll bar

  1. #1
    Join Date
    Sep 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QPlainTextEdit inherited + invisibleQTextBlock + INVALID vertical scroll bar

    Hello,

    I am using inherited class from QPlainTextEdit,
    modifications are line numbering and inclusion of QCompleter only

    Now I want to make some code folding,
    for start, I just want to make text folding working, before mixing it up with grammar

    so my problem is, when I fold some lines, using cursor keys in text is relatively ok

    problem is horizontal scroll bar (visible scroll bar, or mouse middle wheel)

    when I am scrolling up (towards line 0), and I am scrolling through hidden lines,
    they are somewhat included, so each click up, all lines scroll one down (wrong), and in place of hidden line, is last visible top line (so doubled now),
    when I move cursor through incorrectly moved lines, they (?refresh) to what they should be, I solved this by calling
    update(); // which calls lineAreaUpdate + viewport()->update();
    so no more rubbish scrolling,
    now you are "dud" clicking arrow up, till you skip all hidden lines, and then it scrolls,
    annoying, but let us say tolerable

    another problem (this post related) is moments when I hide or show lines,
    if all lines are visible (no scroll bar needed), because some are hidden, and I unhide them, scrollbar WILL NOT APPEAR,
    adding empty lines, will make scroll bar to appear, but only to length of added lines (some lines still inaccessible),
    using arrow keys will move cursor on inaccessible lines, but textedit will not scroll (therefore relatively ok), so you can't see them,

    problem solving events are:
    - resize window VERTICALY (horizontaly WILL NOT help)
    - maximize/restore window state
    - backspace out one line
    QPlainTextEdit inherited widget is being resized with window,
    also setPlainText(toPlainText); solve the problem

    so my first question, which event to call, to FORCE scrollbars to refresh their (?state, ?linesCounting),
    second is, what else is wrong and how to correct it (not by using other widgets, I think this is almost done and need only small repair)

    PS: on events when scrollbar (horizontal) correctly resizes, scrolling is working as supposed (no more dud-clicking), therefore I think calling right updateLikeMethodOnScrollsBar could resolve all problems

    here are some sources,
    lineTextEdit is inherited from QPlainTextEdit

    line numbering, correct on folding when update called
    Qt Code:
    1. // process all valid blocks
    2. while (block.isValid() && top <= event->rect().bottom())
    3. {
    4. // print number
    5. if (block.isVisible())
    6. painter.drawText(0, top, lineCntr->width(), fontMetrics().height(), Qt::AlignRight, QString::number(blockNumber));
    7.  
    8. // update data
    9. block = block.next();
    10. top = bottom;
    11. bottom = top + (int) blockBoundingRect(block).height();
    12.  
    13. // next
    14. ++blockNumber;
    15. }
    To copy to clipboard, switch view to plain text mode 


    code colapsing method
    Qt Code:
    1. /// manager of code collapsing
    2. void lineTextEdit::blockMaster()
    3. {
    4. // acquire first block
    5. QTextBlock block(firstVisibleBlock());
    6.  
    7. // default visibility depth
    8. int depth(0);
    9.  
    10. // process all blocks
    11. while (block.isValid())
    12. {
    13. // set visibility
    14. block.setVisible(!depth);
    15.  
    16. // conditions
    17. if (block.text().left(5) == ";HIDE")
    18. ++depth;
    19. else if (depth && block.text().left(5) == ";SHOW")
    20. {
    21. --depth;
    22. block.setVisible(!depth);
    23. }
    24.  
    25. // next block
    26. block = block.next();
    27. }
    28.  
    29. // update
    30. this->viewport()->update();//////// part of lineCntr->update (not directly, but DO IS called)
    31. this->lineCntr->update();//////// currently connected on updateRequest()
    32.  
    33. update();
    34. }
    To copy to clipboard, switch view to plain text mode 
    PS: I do not care about point&click hide/show arrows till this manager is not working properly, this is easier for me to test

  2. #2
    Join Date
    Sep 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPlainTextEdit inherited + invisibleQTextBlock + INVALID vertical scroll bar

    So I traced it to resizeEvent,
    the method needed to call is
    d->relayoutDocument();,
    but is private so i can't call it directly,

    it is bounded by if (old_width != now_width),

    so questions are:
    - how to call private member
    - how to make old_width dirty, as calling resize event is quite simple
    - which other member is calling this private member (of QPlainTextEdit)

    member I traced it in is
    Qt Code:
    1. void QPlainTextEdit::resizeEvent(QResizeEvent *e)
    2. {
    3. Q_D(QPlainTextEdit);
    4. if (e->oldSize().width() != e->size().width())
    5. d->relayoutDocument();
    6. d->_q_adjustScrollbars();
    7. }
    To copy to clipboard, switch view to plain text mode 
    experimentaly verified with debugger (by tikering code flow) that d->_q_adjustScrollbars(); is NOT doing what it is supposed to,
    d->relayoutDocument(); is the one I need,

    So will there be any quick answer for any of my three questions or am I about to look inside the method where more exactly the problem is being solved?

  3. #3
    Join Date
    Sep 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPlainTextEdit inherited + invisibleQTextBlock + INVALID vertical scroll bar

    solved by calling resizeEvent(...) with faked QResizeEvent

Similar Threads

  1. QPlainTextEdit auto scroll
    By faldzip in forum Qt Programming
    Replies: 5
    Last Post: 13th January 2010, 19:11
  2. How to disable vertical scroll bar in QTableWidget
    By grsandeep85 in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2009, 12:07
  3. vertical scroll bar in Qt box.
    By rajveer in forum Qt Programming
    Replies: 1
    Last Post: 22nd October 2008, 08:41
  4. Continously Scroll QPlainTextEdit
    By GimpMaster in forum Newbie
    Replies: 2
    Last Post: 12th September 2008, 18:35
  5. Vertical Scroll Bar - Style Sheet
    By vishesh in forum Qt Programming
    Replies: 2
    Last Post: 18th September 2007, 20:03

Tags for this Thread

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.