admin管理员组文章数量:1122846
void fonttiplineEdit::paintEvent(QPaintEvent *event)
{
QLineEdit::paintEvent(event);
QPainter painter(this);
qDebug() << "event->rect().left():" << event->rect().left()
<< " event->rect().right():" << event->rect().right()
<< " event->rect().top():" << event->rect().top()
<< " event->rect().bottom():" << event->rect().bottom()
<< " event->rect().x():" << event->rect().x()
<< " event->rect().y():" << event->rect().y();
QRectF textRect = event->rect().adjusted(11, 0, 0, 0);;
QString text = m_text;
QFont font("Microsoft YaHei"); // 设置字体
font.setPixelSize(16);
QPen pen(QColor("#3F3E3E")); // 设置画笔颜色
painter.setFont(font);
painter.setPen(pen);
painter.drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, text);
}
I override a paintevent of Qlinedit, so that some texts can be displayed on the left side
Then I created a QLabel, used setMovie to place a gif, and set the background transparent, placing it on top of lineedit
void bindinfoWindow::setstyle()
{
phonelineEdit->setmtext(zh("手机号"));
dingtalklineEdit->setmtext(zh("钉钉"));
m_gifWaitWidget->setFixedSize(ui->mycentralwidget->size());
m_gifWaitWidget->raise();
m_gifWaitWidget->hide();
m_movie = new QMovie(":/VPNClientRes/1920/gif/wait1.gif", QByteArray(), this);
m_gifWaitLabel->setMovie(m_movie);
}
Something strange happened, the text in the override paintEvent was incorrectly displayed in the GIF
It is found through debug that GIF calls Paintevent
This is normal Paintevent
event->rect().left(): 0 event->rect().right(): 302 event->rect().top(): 0 event->rect().bottom(): 35 event->rect().x(): 0 event->rect().y(): 0
event->rect().left(): 0 event->rect().right(): 302 event->rect().top(): 0 event->rect().bottom(): 35 event->rect().x(): 0 event->rect().y(): 0
This is the gif call
event->rect().left(): 178 event->rect().right(): 209 event->rect().top(): 32 event->rect().bottom(): 35 event->rect().x(): 178 event->rect().y(): 32
event->rect().left(): 178 event->rect().right(): 209 event->rect().top(): 0 event->rect().bottom(): 17 event->rect().x(): 178 event->rect().y(): 0
My temporary workaround is to add a line to block the gif call
void fonttiplineEdit::paintEvent(QPaintEvent *event)
{
QLineEdit::paintEvent(event);
QPainter painter(this);
if(event->rect().left() != 0) return; //block gifcall
QRectF textRect = event->rect().adjusted(11, 0, 0, 0);;
QString text = m_text;
QFont font("Microsoft YaHei"); // 设置字体
font.setPixelSize(16);
QPen pen(QColor("#3F3E3E")); // 设置画笔颜色
painter.setFont(font);
painter.setPen(pen);
painter.drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, text);
}
But I don't know the fundamental reason. The QT version I am using is 5.15.2
本文标签: cAfter override painteventQMovie39s transparent background bugStack Overflow
版权声明:本文标题:c++ - After override paintevent, QMovie's transparent background bug - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736305165a1932493.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论