Home

Awesome

QTermWidget

Overview

A terminal emulator widget for Qt 6.

QTermWidget is an open-source project originally based on the KDE4 Konsole application, but it took its own direction later on. The main goal of this project is to provide a Unicode-enabled, embeddable Qt widget for using as a built-in console (or terminal emulation widget).

It is compatible with BSD, Linux and OS X.

This project is licensed under the terms of the GPLv2 or any later version. See the LICENSE file for the full text of the license. Some files are published under compatible licenses:

Files: example/main.cpp
       lib/TerminalCharacterDecoder.cpp
       lib/TerminalCharacterDecoder.h
       lib/kprocess.cpp
       lib/kprocess.h
       lib/kpty.cpp
       lib/kpty.h
       lib/kpty_p.h
       lib/kptydevice.cpp
       lib/kptydevice.h
       lib/kptyprocess.cpp
       lib/kptyprocess.h
       lib/qtermwidget.cpp
       lib/qtermwidget.h
       lib/qtermwidget_interface.h
Copyright: Author Adriaan de Groot <groot@kde.org>
           2010, KDE e.V <kde-ev-board@kde.org>
           2002-2007, Oswald Buddenhagen <ossi@kde.org>
           2006-2008, Robert Knight <robertknight@gmail.com>
           2002, Waldo Bastian <bastian@kde.org>
           2008, e_k <e_k@users.sourceforge.net>
           2022, Francesc Martinez <info@francescmm.com>
License: LGPL-2+

Files: cmake/FindUtf8Proc.cmake
Copyright: 2009-2011, Kitware, Inc
           2009-2011, Philip Lowman <philip@yhbt.com>
License: BSD-3-clause

Installation

Compiling sources

The only runtime dependency is qtbase ≥ 6.6.0. Build dependencies are as follows:

Code configuration is handled by CMake. CMake variable CMAKE_INSTALL_PREFIX will normally have to be set to /usr, depending on the way library paths are dealt with on 64bit systems. Variables like CMAKE_INSTALL_LIBDIR may have to be set as well.

To build, run make. To install, run make install which accepts variable DESTDIR as usual.

To build PyQt bindings, build this library first, and then invoke sip-wheel in pyqt/ directory. Environment variables CXXFLAGS and LDFLAGS can be used to specify non-installed or non-standard directories for headers and shared libraries, and the built Python wheel can be installed by standard tools like pip. See the CI script for a complete example.

Binary packages

The library is provided by all major Linux distributions. This includes Arch Linux, Debian, Fedora, openSUSE and all of their children, given they use the same package repositories. Just use the distributions' package managers to search for string qtermwidget.

Translation

Translations can be done in LXQt-Weblate

<a href="https://translate.lxqt-project.org/projects/lxqt-desktop/qtermwidget/"> <img src="https://translate.lxqt-project.org/widgets/lxqt-desktop/-/qtermwidget/multi-auto.svg" alt="Translation status" /> </a>

API

Public Types

TypeVariable
enumScrollBarPosition { NoScrollBar, ScrollBarLeft, ScrollBarRight }
enumKeyboardCursorShape { BlockCursor, UnderlineCursor, IBeamCursor }

Properties

Public Functions

TypeFunction
QTermWidget(int startnow = 1, QWidget *parent = 0)
virtual~QTermWidget()
voidchangeDir(const QString &dir)
voidgetSelectionEnd(int &row, int &column)
voidgetSelectionStart(int &row, int &column)
voidscrollToEnd()
voidsendText(QString &text)
voidsetArgs(QStringList &args)
voidsetAutoClose(bool enabled)
voidsetColorScheme(const QString &name)
voidsetEnvironment(const QStringList &environment)
voidsetFlowControlEnabled(bool enabled)
voidsetFlowControlWarningEnabled(bool enabled)
voidsetHistorySize(int lines)
voidsetKeyboardCursorShape(QTermWidget::KeyboardCursorShape shape)
voidsetMonitorActivity(bool enabled)
voidsetMonitorSilence(bool enabled)
voidsetMotionAfterPasting(int action)
voidsetScrollBarPosition(QTermWidget::ScrollBarPosition pos)
voidsetSelectionEnd(int row, int column)
voidsetSelectionStart(int row, int column)
voidsetShellProgram(const QString &program)
voidsetSilenceTimeout(int seconds)
voidsetTerminalFont(QFont &font)
voidsetTerminalOpacity(qreal level)
voidsetTerminalSizeHint(bool enabled)
voidsetWorkingDirectory(const QString &dir)
voidstartShellProgram()
voidstartTerminalTeletype()
QStringListavailableColorSchemes()

Public Slots

TypeFunction
voidcopyClipboard()
voidpasteClipboard()
voidpasteSelection()
voidzoomIn()
voidzoomOut()
voidsetSize(const QSize &)
voidsetKeyBindings(const QString &kb)
voidclear()
voidtoggleShowSearchBar()

Signals

TypeFunction
voidactivity()
voidbell(const QString &message)
voidcopyAvailable(bool)
voidfinished()
voidprofileChanged(const QString &profile)
voidreceivedData(const QString &text)
voidsendData(const char*, int)
voidsilence()
voidtermGetFocus()
voidtermKeyPressed(QKeyEvent*)
voidtermLostFocus()
voidtitleChanged()
voidurlActivated(const QUrl &, bool fromContextMenu)

Static Public Members

TypeFunction
static QStringListavailableColorSchemes()
static QStringListavailableKeyBindings()
static voidaddCustomColorSchemeDir(const QString &custom_dir)

Protected Functions

TypeFunction
virtual voidresizeEvent(QResizeEvent*)

Protected Slots

TypeFunction
voidsessionFinished()
voidselectionChanged(bool textSelected)

Member Type Documentation

enum QTermWidget::ScrollBarPosition
This enum describes the location where the scroll bar is positioned in the display widget when calling QTermWidget::setScrollBarPosition().

ConstantValueDescription
QTermWidget::NoScrollBar0x0Do not show the scroll bar.
QTermWidget::ScrollBarLeft0x1Show the scroll bar on the left side of the display.
QTermWidget::ScrollBarRight0x2Show the scroll bar on the right side of the display.


enum QTermWidget::KeyboardCursorShape
This enum describes the available shapes for the keyboard cursor when calling QTermWidget::setKeyboardCursorShape().

ConstantValueDescription
QTermWidget::BlockCursor0x0A rectangular block which covers the entire area of the cursor character.
QTermWidget::UnderlineCursor0x1A single flat line which occupies the space at the bottom of the cursor character's area.
QTermWidget::IBeamCursor0x2A cursor shaped like the capital letter 'I', similar to the IBeam cursor used in Qt/KDE text editors.

Property Documentation

flowControlEnabled : bool
Returns whether flow control is enabled.

getPtySlaveFd : const int
Returns a pty slave file descriptor. This can be used for display and control a remote terminal.

<!--**getShellPID : int**\-->

getForegroundProcessId : int
Returns the PID of the foreground process. This is initially the same as processId() but can change as the user starts other programs inside the terminal. If there is a problem reading the foreground process id, 0 will be returned.

<!--**getTerminalFont : QFont**\-->

historyLinesCount : int
Returns the number of lines in the history buffer.

<!--**icon : const QString**\-->

keyBindings : QString
Returns current key bindings.

<!--**screenColumnsCount : int**\-->

selectedText(bool preserveLineBreaks = true) : QString
Returns the currently selected text.

<!--**sizeHint : const QSize**\--> <!--**terminalSizeHint : bool**\--> <!--**title : const QString**\--> <!--**workingDirectory : QString**\-->

wordCharacters : QString
When selecting text by word, consider these characters to be word characters in addition to alphanumeric characters, default is :@-./_~.

Member Function Documentation

<!--__void activity()__\--> <!--__void bell(const QString &_message_)__\-->

void changeDir(const QString &dir)
Attempt to change shell directory (Linux only).

void clear()
Clear the terminal content and move to home position.

<!--__void copyAvailable(bool)__\-->

void copyClipboard()
Copy selection to clipboard.

<!--__void finished()__\--> <!--__void getSelectionEnd(int &_row_, int &_column_)__\--> <!--__void getSelectionStart(int &_row_, int &_column_)__\-->

void pasteClipboard()
Paste clipboard to terminal.

void pasteSelection()
Paste selection to terminal.

<!--__void profileChanged(const QString &_profile_)__\-->

void receivedData(const QString &text)
Signals that we received new data from the process running in the terminal emulator.

void scrollToEnd()
Wrapped, scroll to end of text.

void sendData(const char*, int)
Emitted when emulator send data to the terminal process (redirected for external recipient). It can be used for control and display the remote terminal.

void sendText(QString &text)
Send text to terminal.

void setArgs(QStringList &args)
Sets the shell program arguments, default is none.

void setAutoClose(bool enabled)
Automatically close the terminal session after the shell process exits or keep it running.

void setColorScheme(const QString &name)
Sets the color scheme, default is white on black.

void setEnvironment(const QStringList &environment)
Sets environment variables.

void setFlowControlEnabled(bool enabled)
Sets whether flow control is enabled.

void setFlowControlWarningEnabled(bool enabled)
Sets whether the flow control warning box should be shown when the flow control stop key (Ctrl+S) is pressed.

void setHistorySize(int lines)
History size for scrolling.

void setKeyBindings(const QString &kb)
Set named key binding for given widget.

void setKeyboardCursorShape(QTermWidget::KeyboardCursorShape shape)
Sets the shape of the keyboard cursor. This is the cursor drawn at the position in the terminal where keyboard input will appear.

<!--__void setMonitorActivity(bool _enabled_)__\--> <!--__void setMonitorSilence(bool _enabled_)__\--> <!--__void setMotionAfterPasting(int _action_)__\-->

void setScrollBarPosition(QTermWidget::ScrollBarPosition pos)
Sets presence and position of scrollbar.

<!--__void setSelectionEnd(int _row_, int _column_)__\--> <!--__void setSelectionStart(int _row_, int _column_)__\-->

void setShellProgram(const QString &program)
Sets the shell program, default is /bin/bash.

<!--__void setSilenceTimeout(int _seconds_)__\--> <!--__void setSize(_const QSize &_)__\-->

void setTerminalFont(QFont &font)
Sets terminal font. Default is application font with family Monospace, size 10. Beware of a performance penalty and display/alignment issues when using a proportional font.

<!--__void setTerminalOpacity(qreal _level_)__\-->

void setTerminalSizeHint(bool enabled)
Exposes TerminalDisplay::TerminalSizeHint.

<!--__void setWorkingDirectory(const QString &_dir_)__\--> <!--__void silence()__\-->

void startShellProgram()
Starts shell program if it was not started in constructor.

void startTerminalTeletype()
Starts terminal teletype as is and redirect data for external recipient. It can be used for display and control a remote terminal.

<!--__void termGetFocus()__\--> <!--__void termKeyPressed(QKeyEvent*)__\--> <!--__void termLostFocus()__\--> <!--__void titleChanged()__\--> <!--__void toggleShowSearchBar()__\--> <!--__void urlActivated(const QUrl &, bool _fromContextMenu_)__\-->

void zoomIn()
Zooms in on the text.

void zoomOut()
Zooms out in on the text.