Remove Arrow Buttons for QSpinBox in Qt 6

Remove Arrow Buttons for QSpinBox in Qt 6

The QSpinBox widget provides a convenient way to input numerical values within a specified range. By default, the QSpinBox comes with arrow buttons that allow users to increment or decrement the value displayed. However, there might be cases where you want to remove these arrow buttons for aesthetic or functional reasons. This tutorial shows how to remove arrow buttons for QSpinBox in Qt 6.

The provided code snippet demonstrates how to create a simple Qt application that utilizes a QSpinBox widget to input numerical values. By setting the button symbols to NoButtons, the arrow buttons associated with the spin box are removed.

#include <QApplication>
#include <QSpinBox>
#include <QVBoxLayout>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    auto *window = new QWidget();
    auto *layout = new QVBoxLayout(window);

    auto *spinBox = new QSpinBox();
    spinBox->setButtonSymbols(QAbstractSpinBox::NoButtons);
    layout->addWidget(spinBox);

    window->setMinimumWidth(200);
    window->show();

    return QApplication::exec();
}

This is the appearance of the spin box:

No arrow buttons for QSpinBox in Qt

Leave a Comment

Cancel reply

Your email address will not be published.