QNewbie
6th June 2014, 23:52
EDIT: For anyone getting this kind of error, override the paintEvent(QPaintEvent*) method..
EDIT 2: The painting is happening as many times as something is drawn in the screen, aint there a way for this to happen only once without adding some bool in there?
Hey all, I've got a project going where I'm trying to learn about clipping regions and painting.
However, I'm stuck.
The code presented below shows the clipped widget. Now, when I try to paint a red line on the borders of the clipped widget, it will, no error thrown, not even try to paint, or am I missing something?
Cargador::Cargador(QWidget *parent) : QWidget(parent,Qt::FramelessWindowHint), ui(new Ui::Cargador) {
ui->setupUi(this);
resize(500,255);
QRegion esquina;
QRegion circulo;
QRegion region(0,0,width(),height(),QRegion::Rectangle);
// SUPERIOR IZQUIERDO
circulo = QRegion(0,0,50,50,QRegion::Ellipse); // Circulo hardcodeado
esquina = QRegion(0,0,25,25,QRegion::Rectangle); // Cuadrado de un cuarto del circulo
region = region.subtracted(esquina.subtracted(circulo));
// INFERIOR DERECHO
circulo = QRegion(width()-50,height()-50,50,50,QRegion::Ellipse);
esquina = QRegion(width()-25,height()-25,25,25,QRegion::Rectangle);
region = region.subtracted(esquina.subtracted(circulo));
setMask(region);
QPixmap logo(":/Cargador/Imagenes/Logo.png",0,Qt::AutoColor);
// qDebug() << logo;
ui->lblLogo->setPixmap(logo);
ui->lblLogo->show();
// Labels transparentes
ui->label->setAttribute(Qt::WA_TranslucentBackground);
ui->label_2->setAttribute(Qt::WA_TranslucentBackground);
ui->lblCargando->setAttribute(Qt::WA_TranslucentBackground);
ui->lblLogo->setAttribute(Qt::WA_TranslucentBackground);
// Borde en negro.
QPainter decorador(this);
//QPolygon poligono;
QPen linea;
QPainterPath zona;
zona.addRegion(region);
linea.setWidth(8);
linea.setColor(Qt::red);
decorador.setPen(linea);
decorador.drawPath(zona);
}
EDIT 2: The painting is happening as many times as something is drawn in the screen, aint there a way for this to happen only once without adding some bool in there?
Hey all, I've got a project going where I'm trying to learn about clipping regions and painting.
However, I'm stuck.
The code presented below shows the clipped widget. Now, when I try to paint a red line on the borders of the clipped widget, it will, no error thrown, not even try to paint, or am I missing something?
Cargador::Cargador(QWidget *parent) : QWidget(parent,Qt::FramelessWindowHint), ui(new Ui::Cargador) {
ui->setupUi(this);
resize(500,255);
QRegion esquina;
QRegion circulo;
QRegion region(0,0,width(),height(),QRegion::Rectangle);
// SUPERIOR IZQUIERDO
circulo = QRegion(0,0,50,50,QRegion::Ellipse); // Circulo hardcodeado
esquina = QRegion(0,0,25,25,QRegion::Rectangle); // Cuadrado de un cuarto del circulo
region = region.subtracted(esquina.subtracted(circulo));
// INFERIOR DERECHO
circulo = QRegion(width()-50,height()-50,50,50,QRegion::Ellipse);
esquina = QRegion(width()-25,height()-25,25,25,QRegion::Rectangle);
region = region.subtracted(esquina.subtracted(circulo));
setMask(region);
QPixmap logo(":/Cargador/Imagenes/Logo.png",0,Qt::AutoColor);
// qDebug() << logo;
ui->lblLogo->setPixmap(logo);
ui->lblLogo->show();
// Labels transparentes
ui->label->setAttribute(Qt::WA_TranslucentBackground);
ui->label_2->setAttribute(Qt::WA_TranslucentBackground);
ui->lblCargando->setAttribute(Qt::WA_TranslucentBackground);
ui->lblLogo->setAttribute(Qt::WA_TranslucentBackground);
// Borde en negro.
QPainter decorador(this);
//QPolygon poligono;
QPen linea;
QPainterPath zona;
zona.addRegion(region);
linea.setWidth(8);
linea.setColor(Qt::red);
decorador.setPen(linea);
decorador.drawPath(zona);
}