setWindowFlags(Qt::FramelessWindowHint|Qt::WindowSystemMenuHint|Qt::WindowMinMaxButtonsHint);
this->setWindowOpacity(0.95);
this->setAttribute(Qt::WA_TranslucentBackground);
QString MainWindow::loadQss(QString szFilePath)
{
QString szQss,line;
QFile file(szFilePath);
if(!file.open(QIODevice::ReadOnly|QIODevice::Text))
{
qDebug()<<"can't open file !"<<endl;
return "";
}
QTextStream txts(&file);
szQss=line=txts.readLine();
while (!line.isNull())
{
line=txts.readLine();
szQss+=line;
}
return szQss;
}
void MainWindow::paintEvent(QPaintEvent *e)
{
QPainter painter(this);
QBrush windowBrush(QColor(228, 238, 250));
QPen windowPen(Qt::NoPen);
painter.setBrush(windowBrush);
painter.setPen(windowPen);
painter.setRenderHint(QPainter::Antialiasing,true);
painter.drawRoundedRect(QRect(0,5,this->width(),this->height()-5),15,15);
painter.drawPixmap(15,8,m_titlePixmap.width(),m_titlePixmap.height(),m_titlePixmap);
painter.setPen(Qt::black);
painter.drawText(40,25,m_szTitle);
}
void MainWindow::mousePressEvent(QMouseEvent *ev)
{
if(ev->button()==Qt::LeftButton)
{
m_ptDrag=frameGeometry().topLeft()-ev->globalPos();
ev->accept();
}
}
void MainWindow::mouseMoveEvent(QMouseEvent *ev)
{
if(ev->buttons()&Qt::LeftButton)
{
if(m_ptDrag!=QPoint(-1,-1))
{
move(ev->globalPos()+m_ptDrag);
}
ev->accept();
}
}
转载于:https://my.oschina.net/u/221120/blog/666893