[qml+pyqt6] Can't get native control appearance

Before I start, know that I’m really trying not to think I know better than anyone, so I apologize if this somehow seems condescending.

I’m trying to learn QML, because KDE’s new convergent framework kirigami is dependent upon it, so the expectation is that it’s the easier, newer, better toolkit. It also allows for multiple backends using different languages. Seems like the perfect improvement.

That’s not been my experience.

For example, when I tried to use the MenuBar {}, Button {}, and Text {} elements, I had to individually mandate that the text be rendered using the platform-native render, since QML’s was awful. There was no QML toggle, and no documented way of using the C++ attribute via python3.

That leads to having to use monstrosities like this

                    Button {
                        /* if (root.visibility != Window.FullScreen {
                            visible: false
                        } */
                        Text {
                            anchors.centerIn: parent
                            text: qsTr("Quit")
                            renderType: Text.NativeRendering
                            color: system_text_color
                        }

Why isn’t native text rendering the default anyway, like it is with QtWidgets?

Anyway, notice the color: system_text_color? That’s a custom property. If I don’t set that, when using breeze-dark, the text is black on dark grey. I therefore have to force it to use the system palette.

    // @origin https://stackoverflow.com/a/59691219/9731176
    SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
    property color system_text_color: myPalette.text

Again, why is this not the default…?


Then there’s just the fact that half of the libraries I’ve installed simply don’t work:

And there’s no documentation on how one is supposed to install a QML library, nor a tool like pip3.


I might just be a really bad programmer, but I’m not having nearly as much trouble with QtWidgets via Python. I want to create adaptive experiences that are cross-platform and depend upon KDE’s newer technologies, but QtQuick+qml seems really difficult.

1 Like

Try that instead:

import QtQuick.Controls 2.15 as QQC2

QQC2.Button {
     text: qsTr("Quit")
}

And the issue is that you are using pyside of pyqt from pip instead of your distro repo which results in Frameworks / QQC2 Desktop Style · GitLab not being used which sets all the reasonable default for a kde app.

2 Likes

Before I start, know that I’m really trying not to think I know better than anyone, so I apologize if this somehow seems condescending.

And yeah, this post is condescending and this sort of behavior is not tolerated. Please be nice and post with good faith in mind.

1 Like

Could you elaborate? I thought saying that sentence would rid the possibility of people misunderstanding, not cause you to think I was being so. I don’t understand.

I genuinely don’t understand what I did that was so wrong. I asked a question, and your kind self provided a great answer. I don’t wanna be banned, since it would be hard to remain part of the community.

I also just genuinely don’t see what the problem(s) are with the post. I’ve spent two days researching, so it shouldn’t sound idiotic.

Thanks, loads. Apologies for coming to such a conclusion since the solution was so simple. I was worried that when I became able to use the Kirigami toolkits, I’d learn that they were reimplementing everything with custom styles rather than using the default system styles.


…However, that solution doesn’t seem to work. After PS /home/rokejulianlockhart> pip3 uninstall pyside6 and then sudo zypper install python3-pyside6, using

                    Text {
                        text: qsTr("Window Actions")
                        renderType: Text.NativeRendering
                        color: system_text_color
                    }

as an example,

// renderType: Text.NativeRendering
color: system_text_color

renderType: Text.NativeRendering
color: system_text_color

renderType: Text.NativeRendering
// color: system_text_color


I’ve converted the app from a QGuiApplication to a QApplication per

but no obvious difference.

If you’re interested, the code is available at

You are using qt6 instead of qt5. Try installing python3-pyside2 instead

Oh! Does the PySide{version} not correspond to the Qt version? I’ll try it.


PS /home/rokejulianlockhart> sudo zypper install python3-pyside2
[sudo] password for root: 
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 18 NEW packages are going to be installed:
  libQt53DAnimation5 libQt53DCore5 libQt53DExtras5 libQt53DInput5 libQt53DLogic5 libQt53DQuick5
  libQt53DQuickAnimation5 libQt53DQuickExtras5 libQt53DQuickInput5 libQt53DQuickRender5 libQt53DQuickScene2D5
  libQt53DRender5 libQt5DataVisualization5 libqt5-qt3d-imports libQt5RemoteObjects5 libQt5Scxml5
  libQt5Scxml5-imports python3-pyside2

18 new packages to install.

Should those be Qt5 libraries? I can’t imagine they’ll help much.


                        // renderType: Text.NativeRendering
                        // color: system_text_color

Imho because your Thread(s) reads more like a Blog post(s) then asking for help.

Summary

Imagine you are a developer and read hundreds of Posts and Bug reports that read more like a blog calling all sorts of things bad and to hard etc…

My suggestion would be to leave your personal opinions outside of help threads. Focus on the technical parts:

  • What do you want to achieve + relevant information.
  • What does not work.
  • What have you already tried to fix it yourself.

Unrelated: Maybe this kind of Dev threads are more fitting in the Development category?

3 Likes

Yeah, I used to use Development, but it doesn’t have the Solutions plugin, per

https://discuss.kde.org/t/enable-the-solved-plugin-on-all-categories-or-allow-setting-help-as-a-tag/1229?u=rokejulianlockhart

and I forget to convert them to Help sometimes. I don’t want to forget and then make some poor sod with the same question have to scroll down the whole thread.


Surely they’re not mutually exclusive? If my grievances were rational, it might have been a useful discussion, but if they turn out to not be, I’ll have at least demonstrated a point of contention when trying to learn kirigami that the documentation doesn’t deal with.

  1. Non-kirigami solution to NativeTextRendering

    from PyQt6.QtQuick import QQuickWindow
    QQuickWindow.setTextRenderType(QQuickWindow.TextRenderType.NativeTextRendering)

…remediates that problem, although I don’t understand how, since I don’t quite see how creating a new QQuickWindow could affect my QApplication.

Comparison

    # from PyQt6.QtQuick import QQuickWindow
    # QQuickWindow.setTextRenderType(QQuickWindow.TextRenderType.NativeTextRendering)

    from PyQt6.QtQuick import QQuickWindow
    QQuickWindow.setTextRenderType(QQuickWindow.TextRenderType.NativeTextRendering)

That works now! How come just specifying the version as QQC2 allowed it to operate correctly?

Additionally, how come

import QtQuick
import QtQuick.Controls 2.15 as QQC2
import QtQuick.Layouts
import QtPositioning

and prepension of QQC2 before Action, Button, ApplicationWindow, and Frame doesn’t work, whereas

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtPositioning
import QtQuick.Controls 2.15 as QQC2

and addition of QQC2.Button (per [qml+pyqt6] Can't get native control appearance - #2 by carl) does?

It was because Text {} isn’t part of that library, and thus text: needs to be used.

It doesn’t matter whether your grievances are rational. Grieving about them in public makes people less likely to help you and more likely to perceive you as a whiner who would rather complain than accomplish anything. This is the way human psychology works.

If you want to learn and accomplish something, ask specific direct questions and stop whining about things not working the way you expect them to work.

2 Likes

I didn’t realize I was whining. I thought my problems must have been part of the toolkit, since I believed I had tried all I could.

Do you all really think I am just being annoying? I’ll accept it if so, but I don’t mean to be… I apologize if I’m posting drivel.

Just ask your questions without all the “ugh, why doesn’t this work?” drama or writing a novel. It will be much more effective at getting actionable answers. If that’s your goal, use the methods that will be most effective at getting you there.

2 Likes

From a higher level, it appears to me that you’re going through “new developer” growing pains. We’ve all been there; it’s understandable. None of this stuff is easy or obvious; it’s like learning a new language. It’s hard.

But like when learning a human language, you just need to learn the quirks. It doesn’t matter why some random vowels in French have a hat over them, or why pronunciation in English is random, or why many languages assign genders to inanimate objects, or why Japanese has two alphabets and also uses random Chinese characters for various words in a way that’s mutually unintelligible with Chinese; these are simply things you need to learn if you want to become proficient in the use of those human languages. It’s the same with programming languages. Try to stop being frustrated by why things don’t work exactly the way you expect and just embrace the fact that stuff is weird and you’ll just need to memorize things. It’ll be a lot easier.

2 Likes

For example, here’s a thing you just need to memorize when using QtQuick:

Never use Text; always use Label. Label is basically Text but it respects the system’s styling. So if you want the system’s styling to be respected, use the thing whose raison d’être is to respect the styling.

So you might then ask, “well, why does Text exist? Wouldn’t I always want to respect the system’s styling?” And maybe you do. I do too. In KDE we generally all do. But QtQuick was made for more than just KDE, and perhaps there are valid use cases for Text.

But for our purposes in KDE, just remember this: “Never use Text; always use Label.”

1 Like

I didn’t see anything wrong with his post. I don’t see what was condescending about it, at all.

There was a a degree of frustration, only to be expected.

I think some people, these days, are just so thin skinned, that everything seems like an insult.

2 Likes

Plasma has its own qml components. These work better than the standard ones IIRC.

I would not suggest using these unless you’re making Plasma widgets :slight_smile: QQC2 + Kirigami is more than enough for most applications

2 Likes

Correct. Plasma components are for Plasma widgets; don’t use them for apps or app-styled config windows.

2 Likes