qml文件中怎么设置透明qml 输入框框

1140人阅读
开发环境:Win7 &Qt5.2.1
1.无边框 &
& &Qt Quick 2.0 中 QQuickView代替了1.0中的QDeclarativeView。
无边框窗口代码如下:
QQuickView
viwer.setFlags(Qt::FramelessWindowHint);
& &这样窗口实现了无边框,但是程序将不会依附在任务栏,如果想同时无边框且图标依附到任务栏,则应该如下设置:
setWindowFlags(Qt::Window|Qt::FramelessWindowHint);
2.窗口透明
& &setOpacity可设置整个窗口(包括控件)的透明度,而背景透明则应使用setColor
viwer.setColor(QColor(Qt::transparent));
3.拖拽窗口
& &拖拽窗口需要将窗口(viewer)设置为qml中的属性
viwer.rootContext()-&setContextProperty(&mainwindow&,&viwer);
& &main.cpp如下
#include&QApplication&
#include&QQuickView&
#include&QColor&
#include&QQmlContext&
int&main(int&argc,char*
&&&&QApplication
app(argc,argv);
&&&&QQuickView
&&&&viwer.setFlags(Qt::FramelessWindowHint);
&&&&viwer.setColor(QColor(Qt::transparent));
&&&&viwer.setSource(QUrl(&qrc:/qml/main.qml&));
&&&&viwer.show();
&&&&viwer.rootContext()-&setContextProperty(&mainwindow&,&viwer);
&&&&return&app.exec();
#include&QApplication&
#include&QQuickView&
#include&QColor&
#include&QQmlContext&
int&main(int&argc,char*
&&&&QApplication
app(argc,argv);
&&&&QQuickView
&&&&viwer.setFlags(Qt::FramelessWindowHint);
&&&&viwer.setColor(QColor(Qt::transparent));
&&&&viwer.setSource(QUrl(&qrc:/qml/main.qml&));
&&&&viwer.show();
&&&&viwer.rootContext()-&setContextProperty(&mainwindow&,&viwer);
&&&&return&app.exec();
& &此时,main.qml如下即可实现透明,无边框,可拖拽
import&QtQuick&2.0
&&&&width:&300
&&&&height:&200
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&color:Qt.rgba(0.5,0.5,0.5,0.9)
&&&&MouseArea
&&&&&&&&id:
dragRegion
&&&&&&&&anchors.fill:
&&&&&&&&property
point clickPos:&&0,0&
&&&&&&&&onPressed:
&&&&&&&&&&&&clickPos&
= Qt.point(mouse.x,mouse.y)
&&&&&&&&&&&&}
&&&&&&&&onPositionChanged:
&&&&&&&&var&delta
= Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
&&&&&&&&mainwindow.setX(mainwindow.x+delta.x)
&&&&&&&&mainwindow.setY(mainwindow.y+delta.y)
& &效果如下:
添加关闭按钮
QtQuick 2.0
&&&&width:
&&&&height:
&&&&color:Qt.rgba(0.5,0.5,0.5,0.9)
&&&&MouseArea
&&&&&&&&id:
dragRegion
&&&&&&&&anchors.fill:
&&&&&&&&property
point clickPos:&&0,0&
&&&&&&&&onPressed:
&&&&&&&&&&&&clickPos&
= Qt.point(mouse.x,mouse.y)
&&&&&&&&&&&&}
&&&&&&&&onPositionChanged:
&&&&&&&&var
delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
&&&&&&&&mainwindow.setX(mainwindow.x+delta.x)
&&&&&&&&mainwindow.setY(mainwindow.y+delta.y)
&&&&Rectangle{
&&&&&&&&id:closeBtn
&&&&&&&&height:
&&&&&&&&width:
&&&&&&&&anchors.right:
parent.right
&&&&&&&&anchors.rightMargin:
&&&&&&&&anchors.top:
parent.top
&&&&&&&&anchors.topMargin:
&&&&&&&&color:&#aaff0000&
&&&&&&&&Text{
&&&&&&&&&&&&text:&x&
&&&&&&&&&&&&anchors.centerIn:
&&&&&&&&MouseArea{
&&&&&&&&&&&&anchors.fill:
&&&&&&&&&&&&onClicked:
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&mainwindow.close()
&&&&&&&&&&&&}
运行效果如图:
本文出自 “” 博客,请务必保留此出处
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:28824次
排名:千里之外
原创:40篇
转载:45篇
(3)(3)(5)(3)(5)(2)(3)(3)(7)(15)(19)(12)(4)(1)(1)
(window.slotbydup = window.slotbydup || []).push({
id: '4740887',
container: s,
size: '250,250',
display: 'inlay-fix'博客访问: 788698
博文数量: 161
博客积分: 5339
博客等级: 大校
技术积分: 1466
注册时间:
IT168企业级官微
微信号:IT168qiye
系统架构师大会
微信号:SACC2013
分类: C/C++
开发环境:Win8.1 &Qt5.2.1
1.无边框 &
& &Qt Quick 2.0 中 QQuickView代替了1.0中的QDeclarativeView。
无边框窗口代码如下:
QQuickView viwer;
//QQuickView继承自QWindow而不是QWidget
viwer.setFlags(Qt::FramelessWindowHint);
& &这样窗口实现了无边框,但是程序将不会依附在任务栏,如果想同时无边框且图标依附到任务栏,则应该如下设置:
setWindowFlags(Qt::Window|Qt::FramelessWindowHint);
2.窗口透明
& &setOpacity可设置整个窗口(包括控件)的透明度,而背景透明则应使用setColor
//设置窗口颜色,以下为透明,在viwer.setSource()之前使用
viwer.setColor(QColor(Qt::transparent));
//QWidget用setAttribute(Qt::WA_TranslucentBackground,true)
3.拖拽窗口
& &拖拽窗口需要将窗口(viewer)设置为qml中的属性
viwer.rootContext()-&setContextProperty("mainwindow",&viwer);
& &main.cpp如下
/*---main.cpp---*/
#include&QApplication&
#include&QQuickView&
#include&QColor&
#include&QQmlContext&
int main(int argc,char* argv[])
&&&&QApplication app(argc,argv);
&&&&QQuickView viwer;
&&&&//无边框,背景透明
&&&&viwer.setFlags(Qt::FramelessWindowHint);
&&&&viwer.setColor(QColor(Qt::transparent));
&&&&//加载qml,qml添加到资源文件中可避免qml暴露
&&&&viwer.setSource(QUrl("qrc:/qml/main.qml"));
&&&&viwer.show();
&&&&//将viewer设置为main.qml属性
&&&&viwer.rootContext()-&setContextProperty("mainwindow",&viwer);
&&&&return app.exec();
& &此时,main.qml如下即可实现透明,无边框,可拖拽
/*--main.qml--*/
import QtQuick 2.0
Rectangle {
&&&&width: 300
&&&&height: 200
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&//灰色0.9透明度
&&&&color:Qt.rgba(0.5,0.5,0.5,0.9)
&&&&MouseArea {
&&&&&&&&id: dragRegion
&&&&&&&&anchors.fill: parent
&&&&&&&&property point clickPos: "0,0"
&&&&&&&&onPressed: {
&&&&&&&&&&&&clickPos = Qt.point(mouse.x,mouse.y)
&&&&&&&&&&&&}
&&&&&&&&onPositionChanged: {
&&&&&&&&//鼠标偏移量
&&&&&&&&var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
&&&&&&&&//如果mainwindow继承自QWidget,用setPos
&&&&&&&&mainwindow.setX(mainwindow.x+delta.x)
&&&&&&&&mainwindow.setY(mainwindow.y+delta.y)
& &效果如下:
添加关闭按钮
import QtQuick 2.0
Rectangle {
&&&&width: 300
&&&&height: 200
&&&&//灰色0.9透明度
&&&&color:Qt.rgba(0.5,0.5,0.5,0.9)
&&&&MouseArea {
&&&&&&&&id: dragRegion
&&&&&&&&anchors.fill: parent
&&&&&&&&property point clickPos: "0,0"
&&&&&&&&onPressed: {
&&&&&&&&&&&&clickPos = Qt.point(mouse.x,mouse.y)
&&&&&&&&&&&&}
&&&&&&&&onPositionChanged: {
&&&&&&&&//鼠标偏移量
&&&&&&&&var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
&&&&&&&&//如果mainwindow继承自QWidget,用setPos
&&&&&&&&mainwindow.setX(mainwindow.x+delta.x)
&&&&&&&&mainwindow.setY(mainwindow.y+delta.y)
&&&&//要置于MouseArea之后,否则无法响应鼠标点击
&&&&Rectangle{
&&&&&&&&id:closeBtn
&&&&&&&&height: 25
&&&&&&&&width: 25
&&&&&&&&anchors.right: parent.right
&&&&&&&&anchors.rightMargin: 5
&&&&&&&&anchors.top: parent.top
&&&&&&&&anchors.topMargin: 5
&&&&&&&&color:"#aaff0000"
&&&&&&&&Text{
&&&&&&&&&&&&text:"x"
&&&&&&&&&&&&anchors.centerIn: parent
&&&&&&&&MouseArea{
&&&&&&&&&&&&anchors.fill: parent
&&&&&&&&&&&&onClicked:
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&//Qt.quit()无法关闭窗口
&&&&&&&&&&&&&&&&mainwindow.close()
&&&&&&&&&&&&}
运行效果如图:
本文出自 “” 博客,请务必保留此出处
阅读(6101) | 评论(0) | 转发(0) |
相关热门文章
给主人留下些什么吧!~~
请登录后评论。温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
喜欢游戏的打朋友
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(1118)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'qt中让应用程序透明, 关闭QML程序',
blogAbstract:'这里是设置使QDeclarativeView 透明,注意目前只在windows xp下测试成功,ubuntu上失败。&&& QDeclarativeV&&& w.setWindowFlags(Qt::FramelessWindowHint);&&& w.setAttribute(Qt::WA_TranslucentBackground);&&& w.setStyleSheet(\"background:transparent\");&&& w.setSource(QUrl(\"../QMLApplication/app.qml\"));&&& w.show();',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:6,
publishTime:0,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'喜欢游戏的打朋友',
hmcon:'-1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}Qt中设置QML窗体无边框和背景透明
编辑:www.fx114.net
本篇文章主要介绍了"Qt中设置QML窗体无边框和背景透明",主要涉及到Qt中设置QML窗体无边框和背景透明方面的内容,对于Qt中设置QML窗体无边框和背景透明感兴趣的同学可以参考一下。
主要代码在(main()函数中)如下:
//设置窗体无边框
view.setWindowFlags(Qt::FramelessWindowHint);
//设置整个窗体背景为透明
view.setAttribute(Qt::WA_TranslucentBackground);
view.setStyleSheet(&background:&);
这里的view可以是:
QDeclarativeView view ;
QmlApplicationViewer view;
上述代码中,设置背景为透明的,必须有(当然也是根据不同需求不一样)这两句,不然的话,背景还是会有白色。
版权声明:本文为博主原创文章,未经博主允许不得转载。
一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!
二、互相尊重,对自己的言论和行为负责。
本文标题:
本页链接:

我要回帖

更多关于 css输入框透明 的文章

 

随机推荐