Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2011-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_QT_GUIUTIL_H6#define BITCOIN_QT_GUIUTIL_H8#include <consensus/amount.h>9#include <net.h>10#include <netaddress.h>11#include <util/check.h>12#include <util/fs.h>14#include <QApplication>15#include <QEvent>16#include <QHeaderView>17#include <QItemDelegate>18#include <QLabel>19#include <QMessageBox>20#include <QMetaObject>21#include <QObject>22#include <QProgressBar>23#include <QString>24#include <QTableView>26#include <cassert>27#include <chrono>28#include <utility>30class PlatformStyle;31class QValidatedLineEdit;32class SendCoinsRecipient;34namespace interfaces35{36class Node;37}39QT_BEGIN_NAMESPACE40class QAbstractButton;41class QAbstractItemView;42class QAction;43class QDateTime;44class QDialog;45class QFont;46class QKeySequence;47class QLineEdit;48class QMenu;49class QPoint;50class QProgressDialog;51class QUrl;52class QWidget;53QT_END_NAMESPACE55/** Utility functions used by the Bitcoin Qt UI.56*/57namespace GUIUtil58{59// Use this flags to prevent a "What's This" button in the title bar of the dialog on Windows.60constexpr auto dialog_flags = Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint;62// Create human-readable string from date63QString dateTimeStr(const QDateTime &datetime);64QString dateTimeStr(qint64 nTime);66// Return a monospace font67QFont fixedPitchFont(bool use_embedded_font = false);69// Set up widget for address70void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent);72/**73* Connects an additional shortcut to a QAbstractButton. Works around the74* one shortcut limitation of the button's shortcut property.75* @param[in] button QAbstractButton to assign shortcut to76* @param[in] shortcut QKeySequence to use as shortcut77*/78void AddButtonShortcut(QAbstractButton* button, const QKeySequence& shortcut);80// Parse "bitcoin:" URI into recipient object, return true on successful parsing81bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out);82bool parseBitcoinURI(QString uri, SendCoinsRecipient *out);83QString formatBitcoinURI(const SendCoinsRecipient &info);85// Returns true if given address+amount meets "dust" definition86bool isDust(interfaces::Node& node, const QString& address, const CAmount& amount);88// HTML escaping for rich text controls89QString HtmlEscape(const QString& str, bool fMultiLine=false);90QString HtmlEscape(const std::string& str, bool fMultiLine=false);92/** Copy a field of the currently selected entry of a view to the clipboard. Does nothing if nothing93is selected.94@param[in] column Data column to extract from the model95@param[in] role Data role to extract from the model96@see TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress97*/98void copyEntryData(const QAbstractItemView *view, int column, int role=Qt::EditRole);100/** Return a field of the currently selected entry as a QString. Does nothing if nothing101is selected.102@param[in] column Data column to extract from the model103@see TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress104*/105QList<QModelIndex> getEntryData(const QAbstractItemView *view, int column);107/** Returns true if the specified field of the currently selected view entry is not empty.108@param[in] column Data column to extract from the model109@param[in] role Data role to extract from the model110@see TransactionView::contextualMenu111*/112bool hasEntryData(const QAbstractItemView *view, int column, int role);114void setClipboard(const QString& str);116/**117* Loads the font from the file specified by file_name, aborts if it fails.118*/119void LoadFont(const QString& file_name);121/**122* Determine default data directory for operating system.123*/124QString getDefaultDataDirectory();126/**127* Extract first suffix from filter pattern "Description (*.foo)" or "Description (*.foo *.bar ...).128*129* @param[in] filter Filter specification such as "Comma Separated Files (*.csv)"130* @return QString131*/132QString ExtractFirstSuffixFromFilter(const QString& filter);134/** Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix135when no suffix is provided by the user.137@param[in] parent Parent window (or 0)138@param[in] caption Window caption (or empty, for default)139@param[in] dir Starting directory (or empty, to default to documents directory)140@param[in] filter Filter specification such as "Comma Separated Files (*.csv)"141@param[out] selectedSuffixOut Pointer to return the suffix (file type) that was selected (or 0).142Can be useful when choosing the save file format based on suffix.143*/144QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir,145const QString &filter,146QString *selectedSuffixOut);148/** Get open filename, convenience wrapper for QFileDialog::getOpenFileName.150@param[in] parent Parent window (or 0)151@param[in] caption Window caption (or empty, for default)152@param[in] dir Starting directory (or empty, to default to documents directory)153@param[in] filter Filter specification such as "Comma Separated Files (*.csv)"154@param[out] selectedSuffixOut Pointer to return the suffix (file type) that was selected (or 0).155Can be useful when choosing the save file format based on suffix.156*/157QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir,158const QString &filter,159QString *selectedSuffixOut);161/** Get connection type to call object slot in GUI thread with invokeMethod. The call will be blocking.163@returns If called from the GUI thread, return a Qt::DirectConnection.164If called from another thread, return a Qt::BlockingQueuedConnection.165*/166Qt::ConnectionType blockingGUIThreadConnection();168// Determine whether a widget is hidden behind other windows169bool isObscured(QWidget *w);171// Activate, show and raise the widget172void bringToFront(QWidget* w);174// Set shortcut to close window175void handleCloseWindowShortcut(QWidget* w);177// Open debug.log178void openDebugLogfile();180// Open the config file181bool openBitcoinConf();183/** Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text184representation if needed. This assures that Qt can word-wrap long tooltip messages.185Tooltips longer than the provided size threshold (in characters) are wrapped.186*/187class ToolTipToRichTextFilter : public QObject188{189Q_OBJECT191public:192explicit ToolTipToRichTextFilter(int size_threshold, QObject *parent = nullptr);194protected:195bool eventFilter(QObject *obj, QEvent *evt) override;197private:198int size_threshold;199};201/**202* Qt event filter that intercepts QEvent::FocusOut events for QLabel objects, and203* resets their `textInteractionFlags' property to get rid of the visible cursor.204*205* This is a temporary fix of QTBUG-59514.206*/207class LabelOutOfFocusEventFilter : public QObject208{209Q_OBJECT211public:212explicit LabelOutOfFocusEventFilter(QObject* parent);213bool eventFilter(QObject* watched, QEvent* event) override;214};216bool GetStartOnSystemStartup();217bool SetStartOnSystemStartup(bool fAutoStart);219/** Convert QString to OS specific boost path through UTF-8 */220fs::path QStringToPath(const QString &path);222/** Convert OS specific boost path to QString through UTF-8 */223QString PathToQString(const fs::path &path);225/** Convert enum Network to QString */226QString NetworkToQString(Network net);228/** Convert enum ConnectionType to QString */229QString ConnectionTypeToQString(ConnectionType conn_type, bool prepend_direction);231/// Convert a duration into a QString with days, hours, mins, secs. This ignores sub-seconds.232QString formatDurationStr(std::chrono::nanoseconds dur);234/** Convert peer connection time to a QString denominated in the most relevant unit. */235QString FormatPeerAge(NodeClock::time_point connected);237/** Format CNodeStats.nServices bitmask into a user-readable string */238QString formatServicesStr(quint64 mask);240/// Format a CNodeStats.m_last_ping_time/m_min_ping_time/m_ping_wait into a user-readable string if it exists, or display N/A241QString formatPingTime(NodeClock::duration ping_time);243/** Format a CNodeStateStats.time_offset into a user-readable string */244QString formatTimeOffset(int64_t time_offset);246QString formatNiceTimeOffset(qint64 secs);248QString formatBytes(uint64_t bytes);250qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal minPointSize = 4, qreal startPointSize = 14);
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.