CustomTextBrowser

class CustomTextBrowser : public QTextBrowser

[0]

Public Functions

CustomTextBrowser(QWidget *parent = nullptr)

This class is used for creating a custom QTextBrowser which supports auto-completion.

Auto-completion suggestions are being shown on the basis of the words stored in the specific language file. It matches by taking the first 3 letters of the words and then gives suggestions whose prefix matches.

Parameters:

QWidget – *parent

~CustomTextBrowser()

Destructor.

void setCompleter(QCompleter *c)

This function sets the completer passed into it and connects the SIGNAL(activated) to the SLOT(insertCompletion).

Parameters:

completer

QCompleter *completer() const

This function returns the pointer to the QCompleter which was set earlier.

Returns:

QCompleter *completer

QAbstractItemModel *modelFromFile(const QString&)

This function takes a filename and reads the data line by line and adds it to an array which it stores in the QStringListModel and returns this model.

Parameters:

fileName

Returns:

QAbstractItemModel *model

Private Functions

QString textUnderCursor() const

This function returns the word under the cursor.

Returns:

QString textUnderCursor

Private Slots

void insertCompletion(const QString &completion)

This function inserts the top-most suggestion in the browser.

Parameters:

completion

void updateGripBand()

This function updates the geometry of rubber band whenever a signal like cursorPositionChanged or value of horizontal and vertical scroll bars is emitted.

void resizeObject(const QRect &rect)

Resizes the image to the geometry of rubber band after the mouse button is released.

Parameters:

rect – Used for resizing the image object to the geometry of this rect