![]() |
The Qt port: versions, keyboard, clipboards and printing | ![]() |
The structure of the Qt port (widgets, UI elements, menus, the event queue, windows, canvases) is described in the Qt implementation, and its renderer in the renderer implementations. This page adds what is specific to the Qt versions and to the input and output channels of the port.
Plugins/Qt compiles with Qt 4, 5 and 6. The differences are handled by about 270 tests of QT_VERSION in the port (most of them QT_VERSION >= 0x060000, < 0x060000 and >= 0x050000) and by a few outside it, for instance in
Texmacs/Texmacs/texmacs.cpp
,
Texmacs/Window/tm_button.cpp
,
Edit/Interface/edit_interface.cpp
and
System/Files/web_files.cpp
. Notable differences are:
High resolution screens. Below Qt 6, TeXmacs manages the scaling itself through the variables retina_factor, retina_zoom, retina_icons and retina_scale, set by the options -retina and -no-retina and the environment variables TEXMACS_RETINA and TEXMACS_RETINA_ICONS (
texmacs.cpp
). With Qt 6 these options do not exist; the device pixel ratio of Qt is used instead (QTMWidget::checkDprChange) and the rounding policy is set to Round at startup.
HTTP requests.
qt_http.cpp
is only compiled in with Qt 6 (#if QT_VERSION >= 0x060000); otherwise http_post falls back to external programs, see system utilities.
The native menu bar. Its default depends on the version and the platform (use native menubar in
texmacs.cpp
); on macOS before Qt 6 it is only used when the preference is force.
Renamed Qt APIs, such as Qt::MidButton versus Qt::MiddleButton or QString::SkipEmptyParts versus Qt::SkipEmptyParts.
gui_version () returns "qt4", "qt5" or "qt6" accordingly (
qt_gui.cpp
). The same code is in
Plugins/Qt6
and in Qtwk (
qtwk_gui.cpp
), so gui-version does not tell Qtwk from Qt. The predicate qt-gui? holds in the two Qt directories and in the Cocoa port, but not in Qtwk, whose widgets are those of Widkit (there x-gui? holds, as in X11), see the overview.
Plugins/Qt6fork
Plugins/Qt6
was created on 2026-05-27 as a copy of Plugins/Qt (commit 73253e50f1, “duplicating qt folder”) and is compiled instead of it by configure --enable-qt-new, which requires Qt 6.10 (see selecting and building a port). Compared with Plugins/Qt it
adds QTMMainTab and QTMMainTabWindow, main windows with tabs which can be moved from one window to another;
changes mostly
qt_http.cpp
,
qt_utilities.cpp
,
qt_tm_widget.cpp
,
QTMToolbar.cpp
and
QTMResponsiveTabWidget.cpp
(31 files differ in total), with work on responsive layouts for small screens and on Android according to the commit messages.
The two directories are kept in sync by hand: changes made in Plugins/Qt are copied over in commits such as bb309fcd50 (“propagating change from Qt dir to Qt6 dir”). A fix in one directory therefore has to be made in the other one too.
Key presses arrive in QTMWidget::keyPressEvent (
QTMWidget.cpp
). A QTMKeyboardEvent translates the Qt key code, modifiers and text into a TeXmacs key combination such as "C-x" or "A-S-left", using the global keyboard settings of QTMKeyboard (
QTMKeyboard.hpp
, held by the application object). An empty combination means that the key is ignored. Otherwise qt_gui_rep::process_keypress queues a QP_KEYPRESS event, which the event loop later delivers to the editor; from there on the key is handled by the keyboard configuration of the server, see keyboard configuration.
Input methods (accents, Chinese and Japanese input, the macOS character palette, dictation) go through QTMWidget::inputMethodEvent:
Committed text is replayed character by character as synthetic key presses (kbdEvent). When the speech preference is on and no preedit is in progress, it is sent instead as one key "speech:text", which handle_speech in
Edit/Interface/edit_keyboard.cpp
interprets.
Preedit text is sent as the key "pre-edit:pos:text", where pos is the cursor position inside the preedit string (an empty string ends the preedit). Scheme handles these keys with delayed-keyboard-press.
QTMWidget::inputMethodQuery tells the input method where the cursor is, so that candidate windows are placed next to it.
For Qt 4 on macOS, a table in inputMethodEvent converts the committed characters of a few Option key combinations back into key presses; this hack only works for standard US keyboards.
The TeXmacs clipboards are named; the Qt port maps "primary" to the system clipboard (QClipboard::Clipboard) and "mouse" to the selection clipboard of X11 (QClipboard::Selection) when the platform supports it. All other names are purely internal: they are stored in the hash tables selection_t and selection_s of qt_gui_rep and never reach the system.
Edit/Replace/edit_select.cpp
), computes sv for the format default in every port; Qtwk publishes the same QMimeData (qtwk_gui_rep::set_selection).
print-buffer (
texmacs/texmacs/tm-files.scm
) uses a dialog only if use-print-dialog? holds, that is, when qt-gui? or vue-gui? holds and the preference gui:print dialogue is on. Otherwise it calls print, which typesets the document to PostScript or PDF and sends the file to the printing command (set-printing-command).
With the dialog, interactive-print-buffer first prints to the file $TEXMACS_HOME_PATH/system/tmp/tmpprint.suffix and then opens widget-printer in an alternative window (interactive-print in
kernel/gui/menu-widget.scm
). In Qt this widget is a qt_printer_widget_rep (
qt_printer_widget.cpp
) showing a QTMPrintDialog. As the comment of that file says, all options are applied as a postprocessing of the already typeset file: QTMPrinterSettings::toSystemCommand turns them into a command line which is run with qt_system. On macOS and Linux the settings class is CupsQTMPrinterSettings, which queries the printers with lpoptions (asynchronously, since it may use the network) and prints with the printing command of TeXmacs or lp and CUPS options (-o orientation-requested, -o sides, -o number-up, -o page-ranges, …); on Windows it is WinQTMPrinterSettings.
The other ports with a print dialog have their own printer_widget: Vue a dialog of Clay widgets which also queries lpoptions and prints with lpr (the Vue port), and Cocoa the print panel of macOS (the Cocoa port). In Qtwk, qt-gui? does not hold, so use-print-dialog? is false and the Widkit placeholder printer_widget is never opened: printing goes through the printing command, as in X11.