Display bug when moving a transparent window QtQuick - qt

So for my current project I need to use a transparent window.
On the creation of the window no problem it works is when you move the window that there is a problem.
The transparency does not apply because it considers that the window is part of the background and reproduces it in the new rendering.
I do not know if I'm very clear I put a picture in link it's more speaking sorry for the quality I had to take it with the laptop because when we capture it "refresh" the display and transparency becomes normal again.
Another surprising thing is that the transparency does not bug if what is behind is chrome ...
So basically the question is how to have a "normal" behavior?
Here I hope that you can help me I see no solution there.
At the code level:
main.cpp :
#include <QQuickView>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QQuickView * view = new QQuickView;
view->setTitle("Test");
view->setSource(QUrl::fromLocalFile ("main.qml"));
view->setColor(Qt::transparent);
view->show();
return a.exec();
}
main.qml :
import QtQuick 2.0
Rectangle {
width: 400
height: 400
color : "#00000000"
Rectangle {
anchors.centerIn: parent
color: "red"
width: 100
height: 100
}
}
Result

Related

QtWebEngine displays partially without margins

WebEngineView should be displayed in the whole window, but it's not. Right margin strip and bottom margin strip is not displayed. Instead a strip of (red) background is visible. Yet I can click on red background on the input search formular and it can be filled. There shouldnt be any background visible.
I also tried QWebEngineView instead of QQmlApplicationEngine and it is exactly the same.
This code is run by Qt 6.4.0.
In Qt 5.12.5 it is displayed correctly.
What to do to show WebEngineView in the whole window ?
main.cpp:
int main(int argc, char *argv[])
{
QtWebEngineQuick::initialize();
QApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/webengine.qml")));
return app.exec();
}
webengine.qml:
import QtQuick
import QtQuick.Window
import QtWebEngine
Window {
width: 800
height: 600
visible: true
color: "red"
WebEngineView {
id: webEngineView
anchors.fill: parent
url: "https://doc.qt.io/qt-6/qtwebengine-webenginequick-minimal-example.html"
}
}
The gui:
This should already be fixed in 6.4.0, was this observed during the beta, if so, then try with the final release. If observed with the final, please open a bug report for at Qt.

Border changes width depending on rectangle width

I have a rounded rectangle in QML code and I noticed strange behavior of rectangle's border, when I resize the rectangle its border appears to be flickering a little and if I look closely I can see that its border seems to be changing its width from 1 to 2 and back or something like that, while in code it definitely set to 1 and doesn't depend on anything else. Also rectangle corners seem to be a little bit wider than border at straight sections. I tried to take screenshots of such rectangles but on the screenshots rectangles looks alright so I suppose it may be some rendering issue? It definitely noticeable in the app. On screenshots you can see that the second rectangle has its borders a little bit blurry, thats when the border appears to be wider than normal.
Is this a known problem and are there any settings in Qt I need to change to get consistent border width on my elements?
I'm using Qt 5.15, QML, C++. I could reproduce this behavior on Windows 10 on two different 1440p monitors.
Edit:
Since my main project is pretty big I will provide example project where I was able to reproduce the issue:
main.cpp
#include <QGuiApplication>
#include <QSurfaceFormat>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
#if defined(Q_OS_WIN)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
main.qml:
import QtQuick 2.9
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Rectangle
{
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
width: parent.width / 3
height: parent.height / 3
color: "#F8F8F8"
radius: 8
border
{
color: "red"
width: 1
}
Text
{
id: valueField
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
font.pointSize: 10
text: "100"
color: "black"
}
}
}
The problem is reproducable when width and height of rectangle are bound to width and height of window, if I set them to one specific value - no such issue is present.
I found that if I do height: Math.round(parent.height / 3) instead of simple height: parent.height / 3, then the issue is gone. As per the comment from #DFaller :
I believe you are correct that this is the solution - QML accepts floats for size but seems to render only in integers, which can causes rounding issues where borders show as either 0 or 2 pixels instead of 1. Rounding as you did has fixed this issue for me in the past.
So posting this as the answer for now.

How to recieve Qt signal entered() in MouseArea from Touch?

I use MouseArea for buttons in my QT app and need to know, when the user moves his finger on the touch on a button. On W7 using a mouse, I get this information with onEntered from MouseArea.
The problem: on the target platform with touchscreen, the entered-signal is only fired, when I press the MouseArea (first touch inside MouseArea), then move my finger out (exited-signal), then move the finger back in (entered-signal). But when the first touch is outside the area and I enter it, entered-signal is not fired.
I also tried MultiPointTouchArea with onTouchUpdated and onUpdated, same behaviour.
I am using Qt 5.5.1 on embedded linux.
Is there something I can do to make the MouseArea always fire the entered-signal? Or should I use something other than MouseArea or MultiPointTouchArea?
As a workaround I could think of a MouseArea on the complete window, with information where all the buttons are and checking on each positionChanged, if a button was entered, but I'm sure there must be a better solution.
Edit: When using a mouse on target platform, the entered-signal is fired when moving the mouse into the area.
This is my (simplified) code:
main.cpp
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QtQml>
#include "uart_terminal.h"
int main(int argc, char *argv[])
{
system("mount /dev/mmcblk0p1 /mnt/sdcard/");
setenv("QT_QPA_EGLFS_PHYSICAL_WIDTH", "376", 1);
setenv("QT_QPA_EGLFS_PHYSICAL_HEIGHT", "301", 1);
QApplication app(argc, argv);
qmlRegisterType<UART_terminal>("com.uart", 1, 0, "UARTTerminal");
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("applicationDirPath", QGuiApplication::applicationDirPath());
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
main.qml:
Window
{
id: rootWindow
visible: true
width: 1280
height: 1024
Rectangle
{
id: test
color: "red"
width: 300
height: 300
MouseArea
{
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.AllButtons
onEntered:
{
console.log("entered")
test.color = "blue"
}
onExited: test.color = "red"
onCanceled: console.log("canceled")
onPositionChanged:
{
console.log("pos changed, containsMouse", containsMouse)
}
}
/*MultiPointTouchArea
{
anchors.fill: parent
onTouchUpdated: console.log("touch updated")
onUpdated: console.log("touchlist updated")
}*/
}
}
So as I didn't find any other solution, I had to implement the mentioned work around. I put a MouseArea "buttonContainer" on the whole screen, behind all other MouseAreas. Note that I have to propagate the positionChanged signal from each MouseArea, otherwise it won't create my button-entered signal when I started the touch in one button and then enter another one.
onPositionChanged:
{
// propagate event to buttonContainer with absolute mouse position
var position = roundMouseArea.mapToItem(root)
buttonContainer.xOffsetMouse = position.x
buttonContainer.yOffsetMouse = position.y
buttonContainer.positionChanged(mouse)
}
Then in buttonContainer's onPositionChanged I have to check for all Buttons that are currenty visible if they were entered. Don't forget to map each buttons position again with btn.mapToItem(buttonContainer) and to reset x- and yOffsetMouse in buttonContainer's onPressed.
In my case I had to do much more stuff like
check if button is disabled anyways, although visible
remember enteredBtn
set bool for each button if it's already entered from my container, so I don't get entered-signal at each positionChanged while I stay in that button
also check for button exited
set btnPressed true or false accordingly, eg. also at buttonContainer's onReleased
reset enteredBtn to undefined accordingly and check for that, before referencing any method or property of enteredBtn (eg. at buttonContainer's onReleased)
I think that was all. Don't want to copy my whole code here, just mention some aspects you might also need to consider if you have the same issue.

Why does a TextArea with NoWrap always cause an "anchor loop detected" warning?

Why is a TextArea with
wrapMode: TextEdit.NoWrap
always causing
file:///C:/Qt/5.5/mingw492_32/qml/QtQuick/Controls/ScrollView.qml:340:13: QML Item: Possible anchor loop detected on fill.
when I run it?
I am running Qt 5.5 on a 64-bit Windows 7 machine, and compiling with MinGW.
Here is my QML code test.qml:
import QtQuick 2.4
import QtQuick.Controls 1.3
ApplicationWindow {
title: "test window"
width: 500
height: 500
visible: true
TextArea {
wrapMode: TextEdit.NoWrap
}
}
Here is my C++ code main.c:
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QtQml>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/test.qml")));
return app.exec();
}
Even if I add anchors.fill: parent to the TextArea, I still get the warnings.
As a second part of this question, is this warning something I should be worried about, or is it something I can safely ignore?
I think it's a bug from Qt, you can ignore it.
When created, TextArea have a width != 0, even if it's empty. When you enter a text that have an implicitWidth smaller then the (default) width of the TextArea, you will get this warning.
A workaround is to assign the wrapMode property in the Component.onCompleted handler:
Component.onCompleted: wrapMode = TextEdit.NoWrap

QML Window opacity doesn't work when fullscreen

I've experienced a strange problem: when a QML Window is fullscreen, its opacity property doesn't work, so the window stay opaque. When the window isn't fullscreen (e.g. maximized), it works properly.
Do you have any ideas how to deal with this problem?
In fact, I want to animate fullscreen window fading in.
The code:
main.qml
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Window 2.1
Window {
visible: true
visibility: "FullScreen"
opacity: 0.5
Text {
id: text
text: "Hello World"
font.pointSize: 36
color: "#333"
}
}
main.cpp
#include <QApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
return app.exec();
}
I use Qt 5.3 on Windows 8.1.
This is the age-old bug of the Qt/Win combination - windows with an OpenGL context, can't be made transparent without employing trickery. The solution is to embed your QML application in a QQuickWidget and make that transparent and full-screen. There also exists another workaround (using the 'DWM' API, which is nonportable - you can read about it in the bug description).
https://bugreports.qt.io/browse/QTBUG-28214

Resources