Incorrect work Qlabel
-
There's a fragment of the code.
QLabel* lbl = new QLabel; QFont f("Helvetica", 100, QFont::Bold); lbl->setFont(f); QString winString = "<FONT COLOR = GREEN><CENTER>ПРАВИЛЬНО!!!</CENTER><FONT>"; lbl->setText(winString); int NumberLine = 1; QString String1 = ui->lineEdit_1->text(); if(ControlCode(String1, NumberLine)) { //если введенное слово правильное lbl->show(); Sleep(4000); lbl->hide(); }
If you remove the fragment at the end
Sleep и lbl->hide()
, the inscription looks like it should. If these lines are not cleaned, windowlbl
the corresponding size is displayed and there is no writing. Just not. I can't figure out what it is. I'm a starter, if some obvious colic didn't notice, don't scream.UPD:
I've decided on the window. Through the flow of the timer. Now, the window goes exactly as long as I need and safely at the end of the timer's work.
The process code to be introduced into a new flow from the main flow and the same hedre has a flow class.
#ifndef CONGRA_H #define CONGRA_H
#pragma once
#include <QtWidgets>
class Congra : public QObject {
Q_OBJECTsignals:
void hiding();public:
QTimer m_timer;
Congra(QObject* pobj = 0) : QObject(pobj)
{
connect(&m_timer, SIGNAL(timeout()), SLOT(hideSignal()));
}
void startShow(int seconds)
{
m_timer.start(seconds);
}
public slots:
void hideSignal()
{
emit hiding();
}
};class MyThread : public QThread {
Q_OBJECT
public:
MyThread(){}void run() { exec(); }
};
#endif // CONGRA_H
and code fragment from an ancestor flow
1. Connection
QObject::connect(&timerMessage, SIGNAL(hiding()), SLOT(HideWindow()));
2. challenge the bottom flow process
timerMessage.startShow(1500);
3. And a slot in a hedge class of ancestor flow
public slots:
void HideWindow()
{
lbl->hide();
}
-
When calling method
show()
There is an event that is added in the course of events, and then your flow falls asleep and then creates a new event to hide the view. After completion of the method, the main flow will be able to process the course of events and, therefore,label
in fact, it appears and hides at the same time. There are two options for addressing this issue:- After the method is called
show()
Compulsory handling of events byqApp->processEvents()
♪ But that's not the best solution. - Remove the code blocking the main flow into a separate flow. In this case, there will be no problem with updating the GUI annex.
- After the method is called