qt 窗口自绘、鼠标响应拖动窗口
生活随笔
收集整理的這篇文章主要介紹了
qt 窗口自绘、鼠标响应拖动窗口
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
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
總結
以上是生活随笔為你收集整理的qt 窗口自绘、鼠标响应拖动窗口的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: urllib.error.HTTPErr
- 下一篇: 软考中项20140309作业