angelica
angelica

Reputation: 49

How to 'backspace' using a pushbutton

I have a QLabel that updates with digits as push buttons are clicked. Is there a way to delete, or 'backspace' using a push button?

Each push button appends a number (0-9) to the QLabel when clicked using this code:

ui->Label->setText(ui->Label->text() + "1");

is there an easy way to use similar code to delete a digit?

Upvotes: 1

Views: 313

Answers (1)

Gasteizko
Gasteizko

Reputation: 208

Use chopped(int len)[1] as stated you in @Angew's comment:

ui->Label->setText(ui->Label->text().chopped(1));

[1] https://doc.qt.io/qt-5/qstring.html#chopped

Upvotes: 2

Related Questions