I tried to remove drop shadow from QToolTip - qt

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

Related

QML: What happens when anchors.margin and a side margin, like anchors.leftMargin are both set?

I want to specify anchors for all sides using anchors.margins, but set a side anchor, like anchors.leftMargin to a different value.
For example:
Rectangle {
id: rect
width: 100; height: 100
color: "black"
Rectangle {
anchors {
fill: parent
leftMargin: 0
margins: 30
}
color: "lime"
}
}
Which shows:
It seems to work, but is this a feature or a bug waiting to happen? Isn't margins a shortcut that sets all side anchor margins and the fact that it works just due to the order in which bindings are evaluated? If someone modifies the code might anchors.margins overwrite the leftMargin property?
Anchors.margins provides the default value for the more specific margin properties. So, what you are doing is safe and supported.
It is safe to set side anchors and anchors.margins together.
anchors.margins, anchors.leftMargin, anchors.topMargin, anchors.rightMargin, and anchors.bottomMargin are all separate properties. The default value for all side anchors is anchors.margins; assigning undefined to a side anchor reverts it to the anchors.margins value.

Is there a way to set the linear gradient stepwith in QML

I use a linear gradient to colorize a rectangle. On my Display (480px, EGLFS) i can clearly see 16 color-steps (see picture). Is there a way to increase the number of steps to have a more fluid gradient.
bad gradient
Rectangle {
width: 800
height: 480
gradient: Gradient{
GradientStop{position: 1.0; color: "#404040"}
GradientStop{position: 0.0; color: "black"}
}
}
The problem was, that the gradient has more colors than the display can show (850 for 256). This is called colour banding (https://en.wikipedia.org/wiki/Colour_banding).
After reducing the colors by using an indicated .png instead of the gradient it looks ok.

How can I rotate a css cursor

Here is what you need to do in order to have a clear view of what I want
Go on this editor
create a shape
select it
rotate it
place your mouse on one of the resize control point then click
you'll see the cursor rotated with the angle of the shape.
I can't find any CSS properties to achieve this kind of thing, how could this be done?
You can't and it doesn't. It just displays the different resize icons. See for example: http://css-cursor.techstream.org/
I needed a rotating arrow cursor for a carousel. Here's what I came up with:
https://codepen.io/addison912/pen/MWwmpoz
Start by hiding the default cursor in css:
body * {
cursor: none;
}
add the image of the cursor you'd like to use to html:
<div id="cursor">
<img alt="Cursor Arrow" src="https://upload.wikimedia.org/wikipedia/commons/9/9d/Arrow-down.svg"/>
</div>
This image needs to track cursor position:
let currentCursorPos;
let cursorEl = document.querySelector("#cursor");
window.addEventListener("mousemove", event => {
currentCursorPos = { x: event.clientX, y: event.clientY };
cursorEl.style.transform = `translate(${currentCursorPos.x}px, ${currentCursorPos.y}px)`;
})
Now you can rotate the #cursor img as needed.
Yes, in modern browsers (Chrome, Firefox, Safari) you can use an SVG encoded as a data URI as the CSS cursor:
cursor: url("data:image/svg+xml, ... ") 16 16, auto;
Encoding the SVG can be tricky, but is well documented here:
https://codepen.io/tigt/post/optimizing-svgs-in-data-uris
The trick is then modifying the encoded SVG's transform property on the fly:
<svg viewBox="32 32"><g transform="rotate(45, 16, 16)">...</g></svg>
For instance, in the above example you'd swap out 45 for your desired angle.

Image border in QML

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 {
}
}

How to set background for qml gridview in Qt

How to set background of gridview from QML file.
Nest the grid view in a Rectangle and make the delegates of the GridView elements transparent:
Rectangle {
color: "red"
GridView {
delegate: Rectangle {
color: "transparent"
}
}
}
In QML you can compose complex objects by including/nesting widgets/elements within each other.
So for including an image inside a Widget, in your case the GridView, just nest an Image element, inside GridView Element or it's sub elements as required.
GridView {
width: 800
height: 600
Image: {
source: "some-image.png"
}
}
The documentation for GridView has similar and better examples - http://doc.qt.digia.com/4.7-snapshot/qml-gridview.html#example-usage
Also look out for the anchors attribute, which will help you position the image in the parent Element, or otherwise.
Documentation for Image element is available here: http://doc.qt.digia.com/latest/qml-image.html

Resources