Results 1 to 2 of 2

Thread: Creating indent guides for QPlainTextEdit

  1. #1
    Join Date
    Feb 2015
    Posts
    7
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Creating indent guides for QPlainTextEdit

    I am trying to create indentation guides for basic text viewer. Currently I have stopped at following piece of code:

    Qt Code:
    1. def paintEvent(self, event):
    2. font = QtGui.QFont('Courier', 10, QtGui.QFont.Light)
    3. font_metrics = QtGui.QFontMetrics(font)
    4. self.font_width = font_metrics.width('X')
    5. self.font_height = font_metrics.height()
    6. self.setFont(font)
    7.  
    8. painter = QPainter(self.viewport())
    9. #painter.begin()
    10. longest_line = 20
    11. from_top = 0
    12. painter.setPen(QtGui.QColor(0, 100, 200, 200))
    13. for i in range(0, longest_line):
    14. the_x = self.font_width + (i * 4 * self.font_width)
    15. painter.drawLine(the_x, from_top, the_x, from_top + self.font_height)
    16.  
    17. QPlainTextEdit.paintEvent(self, event)
    18. #painter.end()
    19. #self.updateScrollbars()
    20. super(QPlainTextEdit, self).paintEvent(event)
    21. return
    To copy to clipboard, switch view to plain text mode 

    This code is not finished as it seems to me somewhat ugly solution. My question is -- is there any guide, or piece of code I can learn from? It does not matter which language. I also could not find relevant topics in this forum, search results are too verbose.

    And just to clarify, this is what I am trying to reproduce: https://visualstudiogallery.msdn.mic...5-630980e72c30.

  2. #2
    Join Date
    Feb 2015
    Posts
    7
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Creating indent guides for QPlainTextEdit

    For anyone who may search for the solution of the same problem -- I have found example in the following software: http://www.iep-project.org/. It contains pretty much everything you may need for editor.

Similar Threads

  1. QtCreator indent
    By fukjo in forum Qt Tools
    Replies: 1
    Last Post: 20th July 2013, 05:45
  2. Qt Quick Developer Guides
    By acix in forum Newbie
    Replies: 0
    Last Post: 8th December 2011, 14:44
  3. indent selection in QPlainTextEdit
    By qt_gotcha in forum Newbie
    Replies: 1
    Last Post: 24th August 2010, 19:06
  4. trying to indent
    By jajdoo in forum Newbie
    Replies: 1
    Last Post: 19th July 2010, 23:25
  5. QTreeView indent
    By evgenM in forum Newbie
    Replies: 0
    Last Post: 18th August 2009, 11:53

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.