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:
Leave a Comment
Cancel reply