Solved How to display Label for 30 seconds and then hide it?
-
@MhM93 said:
Really really thanks.
You're welcome, and good luck! :) Please let us know if you want anything clarified.
-
ui->lbl->setVisible(true); before setText
QTimer::singleShot(1000, ui->lbl, &QLabel::hide);
above command just hide the text after 1 second but never blink again.
I want to blink my lbl text continuously until I click to stop button. so how it possible. guide, please me.This is the code in my case
void secBox::on_APush_clicked()
{
// need start fleshingui->flashing_text->setVisible(true); QTimer::singleShot(1000, ui->flashing_text, &QLabel::hide); //QTimer::singleShot(1000, ui->flashing_text, &QLabel::show); // this does not works
}
void secBox::on_BPush_clicked()
{
// need stop fleshing}
-
@Mijaz If you want the label blinking then don't use singleShot - as the name says it just fires once.
Create a QTimer instance, set interval and connect a slot to https://doc.qt.io/qt-5/qtimer.html#timeout -
@jsulm
thanks !
Will you send me an example where this function used, because I am unable to use it. -
@jsulm
I my case, I tried to implement this but it shows error. -
@Mijaz said in How to display Label for 30 seconds and then hide it?:
I my case, I tried to implement this but it shows error.
Which error exactly? Please show your code.
Regards
-
@Mijaz said in How to display Label for 30 seconds and then hide it?:
Will you send me an example
No, because there are already examples (you can find them in the link I sent you before):
See also QBasicTimer, QTimerEvent, QObject::timerEvent(), Timers, Analog Clock Example, and Wiggly Example. -
-
You create a new timer everytime your slot
on_APush_clicked()
is called. Make the timer a member variable and create it once.timer->start()
without parameters should work.Then the only needed step is to create a slot that does whatever you want.
Regards
-
connect(..., ui->flashing_text->setText("..."));
The last parameter to
connect()
must be either a function/method or a lambda, which in turn will execute thesetText()
you show. You cannot have it be the actual function call you are trying. This is the cause of the error message you see.It would help you if you read up on Qt signals & slots, https://doc.qt.io/qt-5/signalsandslots.html.
-
@aha_1980
I have created new simple project. it shows all ok but still not blinking. -
@Mijaz In the screen-shot you posted you still call singleShot!
Did you read the link I posted? There are even examples:QTimer *timer = new QTimer(this); connect(timer, &QTimer::timeout, this, QOverload<>::of(&AnalogClock::update)); timer->start(1000);
Just connect your own slot to timeout and in that slot toggle the label...
-
@MhM93
thank you... -
@RAJALINGAM
can you please share your form window