I'm trying to use Qt 5 with QtDesktop components in Windows 8 x64 and when I build and run app and move mouse, app is crashing with this message in log:
QPainter::begin: A paint device can only be painted by one painter at a time.
It happens only if mouse move in any component, if i have qml like this:
import QtQuick 2.0
import QtDesktop 1.0
Rectangle {
width: 360
height: 360
Button {
text: "testButton"
}
Text {
text: qsTr("Hello World")
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
Qt.quit();
}
}
}
everything will be ok before I move cursor into button. Somebody have any ideas what is it and how i can fix this? It isn't the error in my code because building tests/tableviewmodels and examples/ApplicationTemplate gives the same result
If it important, I use Visual Studio 2010 Express + Qt Creator 2.6.1
PS not sure, but I think I build and run QtDesktopComponents on this PC about two weeks ago and there wasn't this error, and it was windows update after that
UPD
It was Qt Quick Components bug, fixed in https://bugreports.qt-project.org/browse/QTCOMPONENTS-1287
Related
i am trying to create a TextField and when the TextField is appeared i want it to become editible even without clicking the Text area. It appears but without clicking on placeholder text which is text area, it is not becoming active. Here is what i tried
import QtQuick 2.12
import QtQuick.Controls 2.0
Item {
TextField {
id: textFieldTest
placeholderText: "This area should appear as clicked"
anchors.centerIn: parent
focus: true
Component.onCompleted: textFieldTest.forceActiveFocus()
}
}
I've also tried to use
focus: true
and
Component.onCompleted: textFieldTest.forceActiveFocus()
seperately. Also together. But both of them did not work. Which function or feature should i use?
Sometimes, you need to delay it, e.g.
Component.onCompleted: Qt.callLater(textFieldTest.forceActiveFocus)
The reason being, is that other components initializing may also want to change focus. So, you want to delay your request for focus so that "last in wins".
Please share your entire code if possible. It seems some thing else is stealing the focus. In my case this is working:
import QtQuick
import QtQuick.Controls
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
TextField {
id: textFieldTest
placeholderText: "This area should appear as clicked"
anchors.centerIn: parent
focus: true
Component.onCompleted: textFieldTest.forceActiveFocus()
}
}
In Qt5, I frequently used DropShadow (from QtGraphicalEffects) like in
DropShadow {
anchors.fill: button_layer
source: button_layer
visible: button_layer.visible
verticalOffset: 3
radius: 6
samples: 13
color: app.colorScheme.dropShadow
}
but QtGraphicalEffects does not seem to exist in Qt6 anymore.
What can I use in Qt6 to replace DropShadow (and FastBlur, ColorOverlay, LinearGradient)?
I understand there is a import Qt5Compat.GraphicalEffects, which works fine, but it doesn't feel like a longterm solution.
I've been looking everywhere online but cannot find a working solution. When the application is used on a Desktop computer or laptop, it works fine. Mouse clicks are working, it's when we try with a device with a touch screen like surface pro, that's when problems appear.
I have tried adding to the cpp file that calls the QQuickwidget the flag responsible for detecting touch events and it works with some buttons but other widgets or items are not responding.
AppName *AppName::createInstance(QWidget *parent)
{
instanceUsageCounter++;
if (instance == nullptr)
{
ui = new Ui::AppName();
instance = new AppName();
ui->setupUi(parent);
ui->dc_stackWidget->setCurrentIndex(0);
ui->widget_qml->setAttribute(Qt::WA_AcceptTouchEvents);
QCoreApplication::setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents);
}
return instance;
}
Comboboxes for example.
What exactly needs to be added to make the app detect both mouse clicks and touch events and wokr properly? What exactly is missing?
This is a part in my QML code that worked when I added a TapHandler:
RoundButton
{
id: playButton
icon.source: "qrc:/Resourese/Images/Utility/play.png"
icon.color: "white"
icon.height: playButton.height*0.5
icon.width: playButton.width*0.5
width: settingsButton.width
height: width
radius: width/2
x: width + settingsButton.x + parent.width*0.015
y: settingsButton.y
// x: settingsButton.x
// y: height + settingsButton.y + parent.height*0.015
TapHandler
{
gesturePolicy: TapHandler.ReleaseWithinBounds
onTapped: playButtonClicked();
}
onClicked:
{
playButtonClicked();
}
background: Rectangle
{
//border.color: "#14191D"
color: playButton.hovered || playButton.pressed ? "#3a5470":"#5f758d"
width: playButton.width
height: width
radius: width/2
}
}
Here you will see that there is an onClick and above it is the* TapHandler* that was added recently to add the ability for the boutton to be triggerd when touched on a touch screen. This only worked when the flag in the cpp file was added.
Now look at this:
Rectangle
{
id: settingsCell_R7_C3
Layout.fillHeight: true
Layout.fillWidth: true
Layout.columnSpan: 3
Layout.rowSpan: 1
Layout.row: 6
Layout.column: 0
color: "transparent"
Button
{
text: "Save settings"
font.pixelSize: 30
width: parent.width*0.8
height: parent.height*0.7
anchors.centerIn: settingsCell_R7_C3
TapHandler
{
gesturePolicy: TapHandler.ReleaseWithinBounds
onTapped: applySettings()
}
onClicked: applySettings()
}
}
This Rectangle is within a gridlayout that is inside a Pop up when a Round button similar to the above gets clicked it triggers the pop up window that contains the Rectangle above. The button in this Rectangle when touched is within focus, but not triggered.
I implemented QAbstractTableModel + TableView with QtQuick 2.12 as described in the official QT docs.
my QML code:
import QtQuick 2.12
import TableModel 0.1
TableView {
anchors.fill: parent
columnSpacing: 1
rowSpacing: 1
clip: true
model: TableModel {}
delegate: Rectangle {
implicitWidth: 100
implicitHeight: 50
Text {
text: display
}
}
}
QAbstractTableModel implemented in C++ as described in docs.
Now my app displays a table that can be scrolled.
How to (or is it possible to)
add header that stays visible when the table is
scrolled vertically.
make table rows selectable
use different delegates for different columns
?
In terms of official Qt API, most of it is in the process of being written:
HeaderView is currently being developed: https://codereview.qt-project.org/#/c/255424/
Item selections are currently being developed.
https://stackoverflow.com/a/55517337/904422
Someone else might have answers about how to do this from scratch/manually.
I am trying to find out why flicking is not working with a TreeView example on my Raspberry Pi3 with touch screen.
Looking at the qml code of TreeView.qml, e.g.
https://github.com/RSATom/Qt/blob/master/qtquickcontrols/src/controls/TreeView.qml:
BasicTableView {
...
__mouseArea: MouseArea {
id: mouseArea
parent: __listView
width: __listView.width
height: __listView.height
z: -1
propagateComposedEvents: true
focus: true
// If there is not a touchscreen, keep the flickable from eating our mouse drags.
// If there is a touchscreen, flicking is possible, but selection can be done only by tapping, not by dragging.
preventStealing: !Settings.hasTouchScreen
...
}
}
By similarly looking at the qml code for BasicTableView.qml, it seems that behavior is controlled by Settings.hasTouchScreen.
According to:
https://code.woboq.org/qt5/qtquickcontrols/src/controls/Private/qquickcontrolsettings.cpp.html
it corresponds to the following method:
bool QQuickControlSettings1::hasTouchScreen() const
{
const auto devices = QTouchDevice::devices();
for (const QTouchDevice *dev : devices)
if (dev->type() == QTouchDevice::TouchScreen)
return true;
return false;
}
However, in my case, Settings.hasTouchScreen returns false; i.e. the touch screen (although working for the rest), is not
correctly detected by the QML environment, which probably explains why the flicking does not work.
According to https://doc.qt.io/qt-5/qtouchdevice.html, my touch device should have been registered somehow by the private QWindowSystemInterface::registerTouchDevice() method, but wasn't.
How can I get this to work?
Thanks!
It seems not to work correctly with tslib, but works by using the evdevtouch plugin which is enabled by adding the following command line arguments when launching the program:
-plugin evdevtouch:/dev/input/eventX
where eventX is the event assigned to the touch input.
With that, QTouchDevice::devices() is no longer empty, and the flicking of the TreeView works.