Image border in QML - qt

I want to have an animated border over an Image. But to my surprise, only Rectangle is able to provide border. I want to have a dotted line moving round the Image. How to get such animation. This is my sample code which just provide a border to the Image.
Rectangle {
width: image.width + 5
height: image.height + 5
border.color: "yellow"
border.width: 5
color: "transparent"
Image {
id: image
anchor.centerIn: parent
source: ""
}
}

Because Canvas element in QML does not have the setLineDash() method as JavaScript canvas has (but you can still emulate it, see here), the easiest way (imho) is to use BorderImage with a custom image with dotted pattern. Please see example how to use BorderImage here.
Also you can write your own QML element derived from QQuickPaintedItem or QQuickItem in C++.

Take BorderImage instead of Rectangle:
Image {
BorderImage {
}
}

Related

I tried to remove drop shadow from QToolTip

I want to modify the style of all the tool tip windows in my application.
Please help to make it
I think there's only a dirty hack for this: Set the background as transparent and duplicate the background then. E.g.
ToolTip{
background: Rectangle{id: bg; color: Qt.rgba(0,0,0,0); }
}
Rectangle{
id: realBg
x: bg.x
y: bg.y
width: bg.width
height: bg.height
color: Qt.rgba(1,1,1,1)
}
I know it's ugly, but it works.. I used this technique to make custom shadows using a Canvas element instead of a Rectangle as BG

Bounce effect in a ComboBox QML

I am trying to change the color of the background of the comboBox when pulling till you have a "bounce effect". Cause my background color in the comboBox is black but on the bounce effect the background of the background is white.
If it's not possible I would at least want to be able to desactivate this effect "bouncing effect".
I tried as describe here but it didn't work.
Thanks in advance for your help.
The white background you are seeing is from the popup property embedded in the ComboBox, specifically its background.color. To customize this, the documentation recommends you re-implement the entire popup as well as its ListView contentItem. Re-implementation of this type can be quite painful as you must re-implement all behaviors as well as visual characteristics. I find this to be overkill when you only want to tweak a property or two that already exists.
An easier way is to set the properties at runtime. Here is a working example that shows how to modify your "bounce effect" color as well as modify effect itself:
ComboBox {
id: comboBox
model: ["first", "second", "third"]
delegate: Rectangle { // My remake of your black-background delegates
color: "black"
implicitHeight: 20
implicitWidth: comboBox.width
Text {
anchors {
centerIn: parent
}
text: modelData
color: "lime"
}
}
// At runtime, reach into the comboBox.popup and set the background and boundsBehavior:
Component.onCompleted: {
comboBox.popup.background.color = "black" // Set "bounce" background color to black
comboBox.popup.contentItem.boundsBehavior = Flickable.StopAtBounds // Change/stop "bounce" behavior
}
}

Framing VideoOutput item in Qt QML

I am using a VideoOutput item, which I have placed inside a Rectangle. This VideoOutput goes on top of the Rectangle, of its border and its rounded corners.
Rectangle{
radius: 12
width: 200
height: width
border.color: black
border.width: 15
VideoOutput {
fillMode: VideoOutput.PreserveAspectCrop
anchors.fill: parent
source: myCamera
autoOrientation: true
}
}
Camera {
id: myCamera
focus {
focusMode: CameraFocus.FocusContinuous
focusPointMode: CameraFocus.FocusPointAuto
}
captureMode: Camera.CaptureViewfinder
}
I intentionaly made the border thick so it really shows what is going on. The border is hidden by the VideoOutput, and the rounded corners are ignored.
I can imagine that the VideoOutput item would use some acceleration tricks, so it might not play well with standard QML item behaviour. But is there a way get this to work, without adding a filter element, or is this the expected behaviour?

Correct way to change color of a combobox in QML

What is the correct way to change the color in a combobox?
I know that i can do this:
ComboBox {
background: Rectangle {
color:"blue"
}
}
and it turns like this:
but then i lose the focus border (at least it appears when i do tab to go from one control to another) that is normal to appear in the combobox:
What is the solution?
As pointed by folibis we can find the answer to do that in the source
i did the following:
ComboBox {
id:comboBoxCustom
background: Rectangle {
color:"white"
border.width: parent && parent.activeFocus ? 2 : 1
border.color: parent && parent.activeFocus ? comboBoxCustom.palette.highlight : comboBoxCustom.palette.button
}
}

Using leftCorner/rightCorner in TabViewStyle in QML

I am using Qt 5.1 – QML desktop components. For TabView, I want to have my tabs aligned right but the tabbar should start after a button at top-right corner. I am able to align tabs right using:
tabsAlignment: Qt.AlignRight
However, I am not able to place a button at right corner. Tried this but didn’t work.:
padding.right: 60
I saw that in TabViewStyle, we have rightCorner which is set to null. I tried to put in it rectangle or my own custiom button but it didn’t appear:
rightCorner:
Rectangle{
width: 60
height: 60
color: "red"
}
Please help on using rightCorner or solving this problem. Thanks!
After reading through the source code of QtQuick controls, it seems like the corners need to have an implicitWidth as well as an implicitHeight. It does not work with components that only have width and height.
TabView {
anchors.fill: parent
style: TabViewStyle {
rightCorner: Rectangle {
color: "red"
implicitWidth: 20
implicitHeight: 20
}
}
Tab { title: "Tabby" }
Tab { title: "Tabby" }
Tab { title: "Tabby" }
}
I'm having the same problem. All I noticed is that not all components work. A Text{} or an Item{} component work fine, but as you mentioned, a Rectangle{} component can't be added outright, you'd have to wrap it in an Item, like so:
rightCorner: Item{
Rectangle{
width: 60
height: 60
color: "red"
}
}

Resources