Essential Qt Widget Properties

Enabled

Controls the interactive state of a widget. A disabled widget does not process user inputs.

  • isEnabled(): Retrieves the current active state of the widget.
  • setEnabled(bool): Toggles the widget's availability. Pass true to activate, false to deactivate.
CustomWidget::CustomWidget(QWidget *parent)
    : QWidget(parent), ui(new Ui::CustomWidget)
{
    ui->setupUi(this);
    QPushButton *actionBtn = new QPushButton(this);
    actionBtn->setText("Inactive Action");
    if (actionBtn->isEnabled()) {
        actionBtn->setEnabled(false);
    }
}

CustomWidget::~CustomWidget()
{
    delete ui;
}

Geometry

Defines the spatial footprint of a widget, combining position and dimensions into four core values:

  • x: Horizontal position
  • y: Vertical position
  • width: Horizontal size
  • height: Vertical size

The Qt coordinate system places the origin (0,0) at the top-left corner. Increasing x moves right, and increasing y moves down.

  • geometry(): Returns a QRect containing the current x, y, width, and height.
  • setGeometry(QRect) or setGeometry(int x, int y, int width, int height): Applies new spatial bounds.
QRect bounds = ui->targetBtn->geometry();
ui->targetBtn->setGeometry(bounds.x() + 10, bounds.y(), bounds.width(), bounds.height());
// x+ shifts right
// x- shifts left
// y+ shifts down
// y- shifts up

WindowTitle

Manages the text displayed in the window's title bar.

  • windowTitle(): Fetches the current window caption.
  • setWindowTitle(const QString& title): Assigns a new caption to the window.
CustomWidget::CustomWidget(QWidget *parent)
    : QWidget(parent), ui(new Ui::CustomWidget)
{
    ui->setupUi(this);
    this->setWindowTitle("Application Dashboard");
}

WindowIcon

Manages the graphic displayed in the window's title bar and taskbar entry.

  • windowIcon(): Fetches the current QIcon object.
  • setWindowIcon(const QIcon& icon): Applies a specified icon to the window.
#include <QIcon>

CustomWidget::CustomWidget(QWidget *parent)
    : QWidget(parent), ui(new Ui::CustomWidget)
{
    ui->setupUi(this);
    QIcon appIcon(":/resources/logo.png");
    this->setWindowIcon(appIcon);
}

ToolTip

Provides contextual hints when the cursor hovers over a widget.

  • setToolTip(const QString&): Defines the hint text shown on hover.
  • setToolTipDuration(int): Specifies the visibility duration in milliseconds before the hint automatically vanishes.
CustomWidget::CustomWidget(QWidget *parent)
    : QWidget(parent), ui(new Ui::CustomWidget)
{
    ui->setupUi(this);

    ui->confirmBtn->setToolTip("Proceed with the operation");
    ui->confirmBtn->setToolTipDuration(2000);

    ui->cancelBtn->setToolTip("Abort the operation");
    ui->cancelBtn->setToolTipDuration(5000);
}

Tags: Qt C++ gui widgets

Posted on Thu, 27 Aug 2026 16:38:10 +0000 by trauch