首页 > 其他 > 详细

Qt 学习之旅-----自义定窗口界面

时间:2014-03-10 18:36:14      阅读:473      评论:0      收藏:0      [点我收藏+]

          很多时候根据不同的需要   要将界面根据图片做成各种各样的形状的界面

而界面不能和控件一样  直接用png图做border 无法实现  仍旧是方方正正的  

如何制作自义定的窗口界面呢?  

这要用到QPixmap   图像映射


首先在建立窗口时 

    Dialog *w = new Dialog;

    w->setWindowFlags(Qt::FramelessWindowHint);//去边框

    w->setAttribute(Qt::WA_TranslucentBackground);//背景透明

    w->show();


首先在头文件类中声明


private:

    QPixmap*    backgroundPixmap_;


之后重写 paintEvent

void Dialog::paintEvent(QPaintEvent *)

{

    QPainter painter(this);

    painter.fillRect(0, 0, backgroundPixmap_->width(), backgroundPixmap_->height(), *backgroundPixmap_);

}

然后进行映射

    backgroundPixmap_ = new QPixmap(":/new/prefix1/image/1.png");   //映射资源类图片

    this->resize(backgroundPixmap_->width(), backgroundPixmap_->height());

    this->clearMask();//清除原来的图片信息

    this->setMask(backgroundPixmap_->mask());

    this->update();//更新显示

编译  运行 完成

这样 就可以将窗口根据图片来进行设置了


Qt 学习之旅-----自义定窗口界面,布布扣,bubuko.com

Qt 学习之旅-----自义定窗口界面

原文:http://blog.csdn.net/seecandy/article/details/20920073

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!