【精品】Qt相关材料_第1页
【精品】Qt相关材料_第2页
【精品】Qt相关材料_第3页
【精品】Qt相关材料_第4页
【精品】Qt相关材料_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

精品精品 Qt Qt相关材料相关材料 Qt中添加背景图片的方法1 QPalette的方法 include includeint main int argc char argv QApplication app argc argv QFrame frame new QFrame frame resize 400 700 QPixmap pixmap images frame png QPalette palette palette setBrush frame backgroundRole QBrush pixmap frame setPalette palette frame setMask pixmap mask 可以将图片中透明部分显示为透明的f rame setAutoFillBackground true frame show return app exec 注意图片路径怎么表示 我的图片放在该工程下的ima ges文件夹中 存在问题图片可以显示出来 但是图片大小不能和frame大小一致 显示效果不好 具体怎样调整大小 以后再补充 效果如下 设置了 透明的 好像很漂亮 透明部分将我的桌面显示出来了 2 setSt yleSheet方法 非常好用的方法 include includeint main int argc char argv QApplication app argc argv QFrame frame new QFrame frame setObjectName myframe frame resize 400 700 frame setStyleSheet QFrame myframe border image url images frame png frame show return app exec 效果如下注意很漂亮的效果吧 注意代码中红线的 部分噢 设置ObjectName后 才能保证setStyleSheet只作用在我们 的frame上 不影响其子控件的背景设置 之所以用border image而不用background image 还是上面的问题 用background image不能保证图片大小和控件大小一致 图片不能完全显示 这个 以后再补充了 现在还没有找到方法 3 paintEvent事件方法 myframe h文件 ifndef MYFRAME H define MYFRAME H include includeclass MyFrame public QWidget public MyFrame void paintEvent QPaintEvent event endif MYFRAME H myframe cpp文件 include myframe h MyFrame MyFrame void MyFrame paintEvent QPaintEvent event QPainter painter this painter drawPixmap 0 0 400 700 QPixmap image s frame png main cpp文件 include include include myfr ame h int main int argc char argv QApplication app argc argv MyFrame frame new MyFrame frame resize 400 700 frame show return app exec 效果如下注跟前面一样的效果吧 与前面的差别就是 这个背景图片不随着窗口的大小而变化 因为它的固定大小被设置 成 400 700 了 重写QWidget的paintEvent事件 当控件发生重绘事件 比如show 时 系统就会自动调用paintEvent函数 好了 上面是三种设置背景图片的方法 下面我要说一个设置QPush Button的背景图片的方法 用的是setIcon方法 其实QPushButton设 置背景图片也可以用前面三种方法的 不过现在这种Icon方法的看 起来也不错 include includeint main int argc char argv QApplication app argc argv QFrame frame new QFrame QPushButton button0 new QPushButton frame QPushButton button1 new QPushButton frame QPushButton button2 new QPushButton frame QPushButton button3 new QPushButton frame QPushButton button4 new QPushButton frame QPushButton button5 new QPushButton frame frame setObjectName myframe frame resize 400 700 frame setStyleSheet QFrame myframe border image url images frame png button0 setGeometry 60 150 68 68 button1 setGeometry 160 150 68 68 button2 setGeometry 260 150 68 68 button3 setGeometry 60 280 68 68 button4 setGeometry 160 280 68 68 button5 setGeometry 260 280 68 68 QIcon icon QPixmap pixmap0 images SMS png icon addPixmap pixmap0 button0 setIcon icon button0 setIconSize QSize 68 68 button0 setFixedSize pixmap0 size button0 setMask pixmap0 mask QPixmap pixmap1 images EMail png icon addPixmap pixmap1 button1 setIcon icon button1 setIconSize QSize 68 68 button1 setFixedSize pixmap1 size button1 setMask pixmap1 mask QPixmap pixmap2 images Contacts png icon addPixmap pixmap2 butt on2 setIcon icon button2 setIconSize QSize 68 68 button2 setFixedSize pixmap2 size button2 setMask pixmap2 mask QPixmap pixmap3 images Calendar png icon addPixmap pixmap3 butt on3 setIcon icon button3 setIconSize QSize 68 68 button3 setFixedSize pixmap3 size button3 setMask pixmap3 mask QPixmap pixmap4 images GoogleVoice png icon addPixmap pixmap4 b utton4 setIcon icon button4 setIconSize QSize 68 68 button4 setFixedSize pixmap4 size button4 setMask pixmap4 mask QPixmap pixmap5 images AndroidMarket png icon addPixmap pixmap5 button5 setIcon icon button5 setIconSize QSize 68 68 button5 setFixedSize pixmap5 size button5 setMask pixmap5 mask frame show return app exec 效果如下添加动态图片的方法 includeclass TOOTBtn public QPushButton Q OBJECT public TOOTBtn const QStringconnect movie SIGNAL fra meChanged int this SLOT iconChged int movie start setIconSize QSize 64 64 private slots void iconChged int setIcon movie currentPixmap private QMovie movie include main mo c int main int argc char argv QApplication app argc argv QWidget window TOOTBtn btn zoe gif Test Btn btn move 100 100 window show window re size 640 400 window setWindowTitle TOOTzoe Animating Button Test QObject connect return app exec 在背景设置图片的方法 includeclass TOOTBtn public QPushButton Q OBJECT public TOOTBtn const QStringconnect movie SIGNAL fra meChanged int this SLOT iconChged int movie start private slots void iconChged int QTextDocument Text Text setHtml label QPixmap currFrame movie currentPixmap QPixmap pixmap Text size width currFrame height pixmap fill Qt transparent QPainter painter painter drawPixmap pixmap width currFrame width 2 pixmap height currFrame height 2 cur

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论