Display Rectangle outside of parent or Window [duplicate] - qt

I need to have a Popup that stays visible outside the bounds of the main window.
I couldn't find anything in the Qt documentation.
This is the code:
import QtQuick 2.15
import QtQuick.Window 2.2
import QtQuick.Controls 2.12
ApplicationWindow {
id: window
width: 400
height: 400
visible: true
Button {
text: "Open"
onClicked: popup.open()
}
Popup {
id: popup
x: 100
y: 100
width: 300
height: 400
modal: true
focus: true
dim: false
contentItem: Rectangle
{
anchors.fill: parent
color: "red"
}
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
}
}
This is the output of this:
I want the red to go beyond the window borders.
Something like this:
I'd appreciate the help!
Note: using a Dialog is no good for me.

Popups are not proper windows, so you'd need to create a new window like Michael mentioned:
import QtQuick 2.15
import QtQuick.Controls 2.15
ApplicationWindow {
id: mainWindow
width: 640
height: 480
visible: true
ApplicationWindow {
id: redWindow
x: mainWindow.x + mainWindow.width / 2
y: mainWindow.y + mainWindow.height / 2
width: 300
height: 400
flags: Qt.Popup | Qt.Dialog
visible: true
Rectangle {
color: "red"
anchors.fill: parent
}
}
}
There is a suggestion to make Popups proper windows here.

Related

QML window is bouncing while changing size and position

My purpose is to glue the window to the right alignment of the screen while resizing.
During animation (or changing explicity) of window width and x (binded to width), ApplicationWindow is bouncing to left (flickering for changing explicity).
I've already was searching for the solution, but nothing is working for me.
Adding the attribute:
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
helped a lot, but window is still bouncing to left and right.
main.qml:
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QtQuick.Controls.Material 2.15
ApplicationWindow {
id: root
height: 300
width: 300
visible: true
flags: Qt.FramelessWindowHint
x: Screen.width - width
Material.theme: Material.Dark
NumberAnimation on width {
id: animation
easing.type: Easing.InOutQuad
}
property var lowerSize: true
Rectangle {
anchors.fill: parent
Button {
anchors.centerIn: parent
enabled: !animation.running
text: lowerSize ? 'Size up' : 'Size down'
onClicked: {
animation.from = lowerSize ? 300 : 600
animation.to = lowerSize ? 600 : 300
animation.start()
lowerSize = !lowerSize
}
}
}
}
I've made example code for reproducing the issuee on github qml-flickering-example.
I had slightly different behavior on macOS than you are seeing in Windows (stutters on shrink for me) but it does indeed still stutter.
It appears to be because you are animating the width but then relying on QML bindings to update x. As a result, the x update is lagging behind the width update by one frame.
Using a ParallelAnimation and animating both at the same time fixed it for me:
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QtQuick.Controls.Material 2.15
ApplicationWindow {
id: root
height: 300
width: 300
visible: true
flags: Qt.FramelessWindowHint
Component.onCompleted: {
x = Screen.width - width;
y = 0;
}
Material.theme: Material.Dark
ParallelAnimation {
id: animation
NumberAnimation {
id: widthAnimation
target: root
property: "width"
easing.type: Easing.InOutQuad
}
NumberAnimation {
id: xAnimation
target: root
property: "x"
easing.type: Easing.InOutQuad
}
}
property bool lowerSize: true
Rectangle {
anchors.fill: parent
Button {
anchors.centerIn: parent
enabled: !animation.running
text: lowerSize ? 'Size up' : 'Size down'
onClicked: {
widthAnimation.from = lowerSize ? 300 : 600
widthAnimation.to = lowerSize ? 600 : 300
xAnimation.from = lowerSize ? Screen.width - 300 : Screen.width - 600
xAnimation.to = lowerSize ? Screen.width - 600 : Screen.width - 300
animation.start()
lowerSize = !lowerSize
}
}
}
}

How to use Material.elevation and Radius in a Pane?

I'm trying to use a Pane which I add Material.elevation: 6 but in turn I want to give it a rounded edge and I can not get both together at the same time
The following is attempted but the elevation is lost.
Pane {
// ...
Material.elevation: 6
background: Rectangle {
radius: 15
}
// ...
}
The idea is that you can keep both aspects to achieve something like:
You have to overwrite based on the source code:
RoundPane.qml
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Controls.Material 2.12
import QtQuick.Controls.Material.impl 2.12
Pane {
id: control
property int radius: 2
background: Rectangle {
color: control.Material.backgroundColor
radius: control.Material.elevation > 0 ? control.radius : 0
layer.enabled: control.enabled && control.Material.elevation > 0
layer.effect: ElevationEffect {
elevation: control.Material.elevation
}
}
}
IconPane.qml
import QtQuick 2.12
import QtQuick.Controls.Material 2.12
import QtQuick.Layouts 1.12
RoundPane {
id: control
property alias name: txt.text
property alias icon: image.source
Material.elevation: 6
radius: 15
RowLayout{
anchors.fill: parent
Image {
id: image
sourceSize.height: parent.height
}
Text {
id: txt;
}
}
}
main.qml
import QtQuick 2.9
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
IconPane{
name: "Stack <b>Overflow</b>"
icon: "https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.svg"
anchors.centerIn: parent
}
}

How change circular progress bar in QML Dial?

I have a problem with changing progress bar color in QML Dial Component. I tried to use Canvas but finally i did nothing. Any suggestions or examples?
Dial {
value: 0.5
anchors.horizontalCenter: parent.horizontalCenter
}
black progress bar
As indicated in this another answer you can use palette, for this you can check the source code, so the solution is:
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.5
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Dial {
// #disable-check M17
palette.dark: "red"
value: .5
anchors.centerIn: parent
}
}
Another way to change the color of an Item is ColorOverlay, which has RGBA support.
https://doc.qt.io/qt-5/qml-qtgraphicaleffects-coloroverlay.html#details
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.5
import QtGraphicalEffects 1.12
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Dial {
id: dial
value: .5
anchors.centerIn: parent
}
ColorOverlay {
anchors.fill: dial
source: dial
color: "#80800000"
}
}

Virtual Keyboard Only Visible when I touch the editable part of screen and not on mouse click

I working on a qt qml application and I want to use the virtual keyboard feature of qt quick. But I want the virtual keyboard to appear only when I touch my laptop screen. The current solution of mine brings virtual keyboard up even when I click mouse on the editable area.
I tried to a lot but couldnt get close to solution. I was thinking of suppressing the mouse click event on the Input Panel but couldnt figure out how
import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
import QtQuick.Layouts 1.1
import QtQuick.VirtualKeyboard 2.1
import QtQuick.Window 2.12
ApplicationWindow {
visible: true
width: 720
height: 480
minimumWidth: 400
minimumHeight:350
TabView {
id:frame
anchors.fill: parent
style: myTabViewStyle
implicitHeight: 100
Tab{
id: setupPage
objectName:"TabParentOfSetup"
enabled: true
title: "Setup"
active: true
SetupTab { }
}
Tab{
id:tabletab
objectName: "TabParentOfTable"
title: "Table"
TableTab{}
}
}
statusBar: StatusBar
{
Label{
id: label
}
}
InputPanel {
id: inputPanel
y: Qt.inputMethod.visible ? parent.height - inputPanel.height :
parent.height
anchors.right: parent.right
anchors.left: parent.left
}
}

Shadow for qml frameless windows

I have frameless main window, created by qml ( ApplicationWindow {..} in my main.qml file)
I instantiate qml by QQmlApplicationEngine::load (class introduced in Qt5.1).
If I set the Qt.FramelessWindowHint flag, the window is frameless, but loses shadow (in Windows).
How to add shadow to my window?
My window listing:
ApplicationWindow {
id: rootWindow
color : "#f8f8f8"
maximumHeight: 445
minimumHeight: 445
minimumWidth: 730
maximumWidth: 730
flags : Qt.FramelessWindowHint | Qt.Window
Component.onCompleted: {
setHeight(455)
setWidth(740)
}
MainObject{
id:mainObject1
anchors.fill: parent
height:445
width:730
}
}
The solution is to implement the shadow part integral to the application, this way you can disable WM decoration and still have decoration, and have it consistent across different platforms.
In the following example the window has a shadow that even animates to create the effect of lifting the window up when moving it. And when the window is maximized, the margins are removed and the shadow is thus no longer visible.
import QtQuick 2.7
import QtQuick.Controls 2.1
import QtGraphicalEffects 1.0
import QtQuick.Window 2.3
ApplicationWindow {
id: main
visible: true
width: 300
height: 200
color: "#00000000"
flags: Qt.FramelessWindowHint | Qt.Window
Rectangle {
id: rect
anchors.fill: parent
anchors.margins: main.visibility === Window.FullScreen ? 0 : 10
MouseArea {
id: ma
anchors.fill: parent
property int dx
property int dy
onPressed: { dx = mouseX; dy = mouseY }
onPositionChanged: {
main.x += mouseX - dx
main.y += mouseY - dy
}
onDoubleClicked: main.visibility = main.visibility === Window.FullScreen ? Window.AutomaticVisibility : Window.FullScreen
}
}
DropShadow {
anchors.fill: rect
horizontalOffset: 1
verticalOffset: 1
radius: ma.pressed ? 8 : 5
samples: 10
source: rect
color: "black"
Behavior on radius { PropertyAnimation { duration: 100 } }
}
}
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import QtGraphicalEffects 1.0
ApplicationWindow{
id: window
visible: true
width: 640
height: 480
title: qsTr("Hello World")
flags: Qt.Window | Qt.FramelessWindowHint
color: "#00000000"
Rectangle {
id: rect
anchors.fill: parent
anchors.margins: 10
radius: 5
}
DropShadow {
anchors.fill: rect
samples: 20
source: rect
color: "gray"
}
}
If you mean the drop shadow effect, that is not quite so.
We have no control over the WM decoration in Qt besides the frameless window flag you have just used. It is pretty much WM specific. Windows (TM) WM applies shadow effect to decorate windows, but this is a Windows (TM) choice. Also, you have just hinted that it should not decorate.

Resources