Qt——QCef框架,加载web页,Qt外壳窗口,无法绘制shandow边框问题。
(2018-10-24 16:00:16)
标签:
it |
1:问题:
2:解决方法:
- 自定义Shadow窗口,实现画边框和圆角。(HHDropShadowWidget)
setAttribute(Qt::WA_DeleteOnClose, true); setAttribute(Qt::WA_TransparentForMouseEvents ); setAttribute(Qt::WA_TranslucentBackground);
重绘事件:
m_iShadowWidth = 8;
m_iRadios = 8;
paintEvent(QPaintEvent *event)
{
QPainterPath path;
path.setFillRule(Qt::WindingFill);
path.addRoundedRect(m_iShadowWidth, m_iShadowWidth, \
this->width()-m_iShadowWidth*2, this->height()-m_iShadowWidth*2, \
m_iRadios, m_iRadios);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
//painter.fillPath(path, QBrush(Qt::white));
QColor color(0, 0, 0, 0);
for(int i=0; i<<SPAN style="COLOR: #800000">m_iShadowWidth; i++)
{
QPainterPath path;
path.setFillRule(Qt::WindingFill);
path.addRoundedRect(m_iShadowWidth-i, m_iShadowWidth-i, \
this->width()-(m_iShadowWidth-i)*2,、
this->height()-(m_iShadowWidth-i)*2, \
m_iRadios, m_iRadios);
int alpha = 38 - i*5;
color.setAlpha(alpha);
painter.setPen(color);
painter.drawPath(path);
}
}
- 自定义ContentWindow窗口,用于承载qcefview加载web页面。(HHShellWgt)
- 在ContentWindow窗口中,创建Shadow窗口。
- 重写void resizeEvent(QResizeEvent *event);
- 重写void moveEvent(QMoveEvent *event);
- 重写void showEvent(QShowEvent *event);
- 重写void hideEvent(QHideEvent *event);
{
if(m_pShadowWgt)
{
QSize s = event->size();
m_pShadowWgt->resize(s.width() + m_iShadowWidth*2, 、
s.height() + m_iShadowWidth*2);
}
}
void HHShellWgt::moveEvent(QMoveEvent *event)
{
if(m_pShadowWgt)
{
QPoint p = event->pos();
m_pShadowWgt->move(p.x() - m_iShadowWidth, p.y() - m_iShadowWidth);
}
}
void HHShellWgt::showEvent(QShowEvent *event) {
if(m_pShadowWgt)
{ m_pShadowWgt->show(); }
}
void HHShellWgt::hideEvent(QHideEvent *event) { if(m_pShadowWgt) { m_pShadowWgt->hide(); } }