I've long noticed page-up and page-down in the body text moves a fixed
15 lines at a time instead of a page at a time.  My body text page
size is never 15 and I find it to be a nuisance.

I found the leoMoveCursorHelper method of the leoQTextEditWidget class
has a linesPerPage parameter which defaults to 15.

def leoMoveCursorHelper (self,kind,extend=False,linesPerPage=15):
    [...]
    if kind in ('page-down','page-up'):
        cursor = w.textCursor()
        cursor.movePosition(op,mode,linesPerPage)
        w.setTextCursor(cursor)
    [...]

I thought this would be easy to fix, but after long effort, I'm
stumped.  I thought this would be easy because out of the box
QTextEdit has the behavior I want.  The page-up and page-down keys
moves one screenful at a time.  Here's some code which shows this:

  import PyQt4.QtGui as QtGui
  w = QtGui.QTextEdit()
  w.resize(250, 150)
  w.move(300, 300)
  w.setWindowTitle('QTextEdit test')
  for n in range(0,300):
    w.insertPlainText('%d\n' % n)
  w.show()
  c.brian_test_w = w
  # Now manually play with page-up, page-down, resize the window, etc.

I expected the docs would tell what the default keybindings are and
what public accessible methods are called by those bindings, but they
just tell the bindings:
http://developer.qt.nokia.com/doc/qt-4.8/qtextedit.html#editing-key-bindings

Maybe my next step should have been to dive into the QT source code,
but I thought that might be a rabbit hole and decided to try internet
searches instead.  I got lost in the maze of QT class documentation
with little to show for it.

I did come up with this code which moves up 1 page:

 sb = w.verticalScrollBar()
 sb.setSliderPosition(sb.sliderPosition() - sb.pageStep())

but that doesn't actually move the text cursor--just the visible page
text.  So the cursor would end up offscreen.  Also, selecting text by
page (i.e. Shift-pageup/Shift-pagedown) would be broken. The method
w.textCursor().movePosition method needs to know the number of lines,
but w.verticalScrollBar().pageStep() returns the number of pixels.  I
don't know how to convert from one to the other.

The answers to any of these questions would be helpful:

1. How to query the number of lines per page from a QTextEdit?
2. How to query the linenumber of the top-most and bottom-most visible
lines in QTextEdit?
3. How to find the height of each visible line in QTextEdit?
4. What code does the default Page-Up/Page-Down code call in QTextEdit?

Does anybody know or know a good way to find out?

Brian

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en.

Reply via email to