2016-10-11 52 views
1

我在QML制作一个自定义分组框中,目前我有这个使矩形disapear的一部分/ QML无形的Qt

Rectangle 
{ 
    anchors.fill: parent 
    color: "#55aaff" 
    Rectangle 
    { 
     id: combo_box 
     anchors.centerIn: parent 
     color: "transparent" 
     width: parent.width/2 
     height: parent.height/2 
     opacity: 0.3 
     Rectangle 
     { 
      anchors.fill: parent 
      color: "transparent" 
      border.color: "#ffffff" 
      border.width: 1 
      radius: 20 
     } 
    } 
    Rectangle 
    { 
     id: combo_box_title 
     anchors.verticalCenter: combo_box.top 
     anchors.left: combo_box.left 
     anchors.leftMargin: 30 
     width: 90 
     height: 20 
     opacity: 0.3 
     color: "#55aaff" 
    } 
    Text 
    { 
     id: combo_box_title_text 
     anchors.centerIn: combo_box_title 
     font.family: "Comic Sans MS" 
     font.pointSize: 9 
     color: "#e1e100" 
     text: "Game Settings" 
    } 

明显显示出像this

你可以看到我的组合框标题有背景中的矩形边框。我想要的只是删除标题后面的Rectangle边框的一部分。

有没有解决我的问题?或者我可以拥有这种GroupBox的任何其他方式。在此先感谢

+0

您可以尝试使用线条的绘制[画布](http://doc.qt.io/qt-5/qml-qtquick-canvas.html) – user2436719

+0

我认为你应该删除大写的文本,因为它看起来不尊重。 – folibis

+0

正在使用适合这种情况的帆布?我有一些矩形,就像你在代码中看到的那样,我会在哪里放置画布?我可以在画布上绘制一条圆形线条,就像你在附件中看到的那样?你能提供一些代码吗?问候 –

回答

2

你用白色边框与Canvas更换Rectangle

Canvas { 
    id: mycanvas 
    anchors.fill: parent 
    onPaint: { 
     var ctx = getContext("2d"); 
     ctx.strokeStyle = 'white'; 
     ctx.beginPath(); 
     ctx.moveTo(120, 0); 
     ctx.lineTo(mycanvas.width - 20, 0); 
     ctx.arc(mycanvas.width - 20,20,20,-Math.PI/2, 0); 
     ctx.lineTo(mycanvas.width, mycanvas.height - 20); 
     ctx.arc(mycanvas.width - 20,mycanvas.height - 20,20,0, Math.PI/2); 
     ctx.lineTo(20, mycanvas.height); 
     ctx.arc(20,mycanvas.height - 20,20,Math.PI/2,Math.PI); 
     ctx.lineTo(0, 20); 
     ctx.arc(20,20,20,Math.PI,-Math.PI/2); 
     ctx.lineTo(30, 0); 
     ctx.stroke(); 
    } 
} 

您可以使用combo_box_title_text.contentWidth,以满足您的文字尺寸完全相同

+0

谢谢你!你让我的生活变得轻松! :) –