No, I'm not saying that. I meant that the error is not triggered feeding QLabel::setText() with the same string.
A very ugly hack I found is the following (after setText() ) :
label->setVisible(false);
label->setVisible(true);
label->setVisible(false);
label->setVisible(true);
To copy to clipboard, switch view to plain text mode
This is a minimal but complete code:
#include <QApplication>
#include <QtGui>
{
Q_OBJECT
public:
~Dialog() {}
private Q_SLOTS:
void buttonClicked();
private:
};
{
QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect(this);
shadowEffect->setBlurRadius(15.0);
shadowEffect
->setColor
(palette
().
color(QPalette::Shadow));
shadowEffect->setOffset(0.0);
m_label->setWindowFlags(Qt::FramelessWindowHint);
m_label->setAttribute(Qt::WA_TranslucentBackground);
m_label->setGraphicsEffect(shadowEffect);
m_label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
layout1->addWidget(m_lineEdit);
layout1->addWidget(m_pushButton);
frame
->setMinimumSize
(QSize(400,
100));
frame->setAutoFillBackground(true);
frame
->setBackgroundRole
(QPalette::Base);
frameLayout->addWidget(m_label);
frameLayout->setContentsMargins(15,15,15,15);
mainLayout->addLayout(layout1);
mainLayout->addWidget(frame);
setLayout(mainLayout);
m_lineEdit->setText("I'm a QLabel");
m_pushButton->setText("&Change");
m_label->setText("I'm a QLabel");
connect(m_pushButton, SIGNAL(clicked()), SLOT(buttonClicked()));
}
void Dialog::buttonClicked()
{
if(!m_lineEdit->text().isEmpty()) {
m_label->setText(m_lineEdit->text());
// uncomment the following to "fix" the issue
// m_label->setVisible(false);
// m_label->setVisible(true);
}
}
int main(int argc, char * argv[])
{
Dialog dialog;
dialog.show();
return app.exec();
}
#include "main.moc"
#include <QApplication>
#include <QtGui>
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
~Dialog() {}
private Q_SLOTS:
void buttonClicked();
private:
QLineEdit *m_lineEdit;
QPushButton *m_pushButton;
QLabel *m_label;
};
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
, m_lineEdit(new QLineEdit(this))
, m_pushButton(new QPushButton(this))
, m_label(new QLabel(this))
{
QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect(this);
shadowEffect->setBlurRadius(15.0);
shadowEffect->setColor(palette().color(QPalette::Shadow));
shadowEffect->setOffset(0.0);
m_label->setWindowFlags(Qt::FramelessWindowHint);
m_label->setAttribute(Qt::WA_TranslucentBackground);
m_label->setGraphicsEffect(shadowEffect);
m_label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
QHBoxLayout *layout1 = new QHBoxLayout;
layout1->addWidget(m_lineEdit);
layout1->addWidget(m_pushButton);
QFrame *frame = new QFrame(this);
frame->setMinimumSize(QSize(400, 100));
frame->setAutoFillBackground(true);
frame->setBackgroundRole(QPalette::Base);
frame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
QGridLayout *frameLayout = new QGridLayout(frame);
frameLayout->addWidget(m_label);
frameLayout->setContentsMargins(15,15,15,15);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(layout1);
mainLayout->addWidget(frame);
setLayout(mainLayout);
m_lineEdit->setText("I'm a QLabel");
m_pushButton->setText("&Change");
m_label->setText("I'm a QLabel");
connect(m_pushButton, SIGNAL(clicked()), SLOT(buttonClicked()));
}
void Dialog::buttonClicked()
{
if(!m_lineEdit->text().isEmpty()) {
m_label->setText(m_lineEdit->text());
// uncomment the following to "fix" the issue
// m_label->setVisible(false);
// m_label->setVisible(true);
}
}
int main(int argc, char * argv[])
{
QApplication app(argc, argv);
Dialog dialog;
dialog.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks