Qt有哪些通用方法及类库
这篇文章主要讲解了“Qt有哪些通用方法及类库”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Qt有哪些通用方法及类库”吧!
成都创新互联公司是一家专注于做网站、成都网站建设与策划设计,田东网站建设哪家好?成都创新互联公司做网站,专注于网站建设10年,网设计领域的专业建站公司;建站业务涵盖:田东等地区。田东做网站价格咨询:028-86922220
函数名
//九宫格图片 horzSplit-宫格1/3/7/9宽度 vertSplit-宫格1/3/7/9高度 dstWidth-目标图片宽度 dstHeight-目标图片高度 static QPixmap ninePatch(const QString &picName, int horzSplit, int vertSplit, int dstWidth, int dstHeight); static QPixmap ninePatch(const QPixmap &pix, int horzSplit, int vertSplit, int dstWidth, int dstHeight);
函数体
QPixmap QUIHelper::ninePatch(const QString &picName, int horzSplit, int vertSplit, int dstWidth, int dstHeight) { QPixmap pix(picName); return ninePatch(pix, horzSplit, vertSplit, dstWidth, dstHeight); } QPixmap QUIHelper::ninePatch(const QPixmap &pix, int horzSplit, int vertSplit, int dstWidth, int dstHeight) { int pixWidth = pix.width(); int pixHeight = pix.height(); QPixmap pix1 = pix.copy(0, 0, horzSplit, vertSplit); QPixmap pix2 = pix.copy(horzSplit, 0, pixWidth - horzSplit * 2, vertSplit); QPixmap pix3 = pix.copy(pixWidth - horzSplit, 0, horzSplit, vertSplit); QPixmap pix4 = pix.copy(0, vertSplit, horzSplit, pixHeight - vertSplit * 2); QPixmap pix5 = pix.copy(horzSplit, vertSplit, pixWidth - horzSplit * 2, pixHeight - vertSplit * 2); QPixmap pix6 = pix.copy(pixWidth - horzSplit, vertSplit, horzSplit, pixHeight - vertSplit * 2); QPixmap pix7 = pix.copy(0, pixHeight - vertSplit, horzSplit, vertSplit); QPixmap pix8 = pix.copy(horzSplit, pixHeight - vertSplit, pixWidth - horzSplit * 2, pixWidth - horzSplit * 2); QPixmap pix9 = pix.copy(pixWidth - horzSplit, pixHeight - vertSplit, horzSplit, vertSplit); //保持高度拉宽 pix2 = pix2.scaled(dstWidth - horzSplit * 2, vertSplit, Qt::IgnoreAspectRatio); //保持宽度拉高 pix4 = pix4.scaled(horzSplit, dstHeight - vertSplit * 2, Qt::IgnoreAspectRatio); //宽高都缩放 pix5 = pix5.scaled(dstWidth - horzSplit * 2, dstHeight - vertSplit * 2, Qt::IgnoreAspectRatio); //保持宽度拉高 pix6 = pix6.scaled(horzSplit, dstHeight - vertSplit * 2, Qt::IgnoreAspectRatio); //保持高度拉宽 pix8 = pix8.scaled(dstWidth - horzSplit * 2, vertSplit); //生成宽高图片并填充透明背景颜色 QPixmap resultImg(dstWidth, dstHeight); resultImg.fill(Qt::transparent); QPainter painter; painter.begin(&resultImg); if (!resultImg.isNull()) { painter.drawPixmap(0, 0, pix1); painter.drawPixmap(horzSplit, 0, pix2); painter.drawPixmap(dstWidth - horzSplit, 0, pix3); painter.drawPixmap(0, vertSplit, pix4); painter.drawPixmap(horzSplit, vertSplit, pix5); painter.drawPixmap(dstWidth - horzSplit, vertSplit, pix6); painter.drawPixmap(0, dstHeight - vertSplit, pix7); painter.drawPixmap(horzSplit, dstHeight - vertSplit, pix8); painter.drawPixmap(dstWidth - horzSplit, dstHeight - vertSplit, pix9); } painter.end(); return resultImg; }
感谢各位的阅读,以上就是“Qt有哪些通用方法及类库”的内容了,经过本文的学习后,相信大家对Qt有哪些通用方法及类库这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!
当前名称:Qt有哪些通用方法及类库
文章起源:http://scyingshan.cn/article/jhdcjh.html