Giter Club home page Giter Club logo

pyqt-line-number-widget's Introduction

pyqt-line-number-widget

Show line numbers next to QTextBrowser or QTextEdit

Requirements

  • PyQt5 >= 5.8

Setup

python -m pip install pyqt-line-number-widget

Example

Code Sample

from PyQt5.QtWidgets import QApplication, QHBoxLayout, QTextEdit, QWidget
from pyqt_line_number_widget import LineNumberWidget


class MainWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.__initUi()

    def __initUi(self):
        self.__te = QTextEdit()
        self.__te.textChanged.connect(self.__line_widget_line_count_changed)
        self.__lineWidget = LineNumberWidget(self.__te)

        lay = QHBoxLayout()
        lay.addWidget(self.__lineWidget)
        lay.addWidget(self.__te)

        self.setLayout(lay)

    def __line_widget_line_count_changed(self):
        if self.__lineWidget:
            n = int(self.__te.document().lineCount())
            self.__lineWidget.changeLineCount(n)


if __name__ == "__main__":
    import sys

    app = QApplication(sys.argv)
    mainWindow = MainWindow()
    mainWindow.show()
    app.exec()

Result

pyqt_line_number_example.mp4

pyqt-line-number-widget's People

Contributors

yjg30737 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

pyqt-line-number-widget's Issues

Add TextEdit as a tab

Hi,
I want to add linenumber to my TextEdit, and add it as a tab:

import os
import sys
root_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
sys.path.append(root_folder)
from PyQt5.QtWidgets import QApplication, QHBoxLayout, QTextEdit, QWidget,QVBoxLayout,QTabWidget
from UI.Line_Number_Widget import LineNumberWidget
from UI.TextEdit import TextEdit
class test(QWidget):
    def __init__(self):
        super().__init__()
        self.__initUi()

    def __initUi(self):
        from UI.MainWindow import MainWindow as uiwinodow
        self.editor_window=uiwinodow()
        self.__te = TextEdit(editor_window=self.editor_window,fileName='file1.c')
        self.__te.textChanged.connect(self.__line_widget_line_count_changed)
        self.__lineWidget = LineNumberWidget(self.__te)
        with open('file1.c', 'r') as f:
            fileData=f.read()
            self.__te.setPlainText(fileData)

        lay = QHBoxLayout()
        self.tabWidget = QTabWidget()
        self.tabWidget.addTab(self.__lineWidget,'test.c')
        lay.addWidget(self.tabWidget)
        self.setLayout(lay)
    def __line_widget_line_count_changed(self):
        if self.__lineWidget:
            n = int(self.__te.document().lineCount())
            self.__lineWidget.changeLineCount(n)


if __name__ == "__main__":
    import sys

    app = QApplication(sys.argv)
    mainWindow = test()
    mainWindow.show()
    app.exec()

But, it just show the number,while there are no texts.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.