Do not repaint QML object - qt

Is there a way to simply tell the object not to repaint? For example so that a Rectangle object will not change color after changing color property.

There's no simple way to do this from QML. I'm not sure that it's even possible to do this in QML; it may be possible in C++.
You can use Canvas instead, which gives you control over when rendering happens.

Related

qt/qml quick item - scale without pixelation

I'm trying to design a zoomable view in qt/qml where you can adjust the scaling of the rendered widgets similar like in a browser or QtWebView.
My first try was to use the scale attribute. Though scaling everything, an unwanted side effect is that the UI gets pixelated.
There exists the QT_SCALE_FACTOR environment variable. The rendered result is what I'm looking for but the scale factor cannot be changed anymore after creating the QGuiApplication.
Additionally it scales everything on the gui, but maybe this issue could be solved if i found a way to manipulate QT_SCALE_FACTOR dynamically at runtime.
I assume that QT_SCALE_FACTOR overrides the QScreen::devicePixelRatio property, but i didn't found a way to manually set this property since it is readonly.
Is there a way to manipulate QT_SCALE_FACTOR at runtime or exists another way to implement such a zoomable view?
With kind regards,
Neconspictor

How to custom the TextArea line background color

I want to compare two TextArea's text ,and change the different text's line background color,but i don't know how can have tow background color in one TextArea. Maybe should custom to get it,what should i do?
or import .js to get it ? what should i do?
As a more advance solution, you can manipulate TextArea content with https://doc.qt.io/qt-5/qtextdocument.html QTextDocument. Original text document is available via this property https://doc.qt.io/qt-5/qml-qtquick-textedit.html#textDocument-prop . From this point, you can assign your own syntax highlighting. But it requires research from your side.
From the other side, you can check this example https://doc.qt.io/qt-5/qtwidgets-widgets-codeeditor-example.html and using this class https://doc.qt.io/qt-5/qsyntaxhighlighter.html you can assign the existing QTextDocument to QSyntaxHighlighter. The same, I guess, can be used for QML TextArea element.
Since TextArea has textDocument property it should be possible re-implement it for QtQuick Constrols.
To be honest I've never dealt with such a task, but this example looks pretty useful for such cases. Probably you should stick with rich text format option suggested in comments if you don't need advanced features (like real-time content changes).

QML Canvas: How to use CanvasWindow and CanvasSize properly

I have a qml canvas with many elements, and when I zoom in, the elements needs to redrawn, if the canvas size grows too much, the rendering is delayed and quite visible.
I couldnt use the canvassize, canvaswindow properly to render only part of the scene, didnt find any proper examples to use this.
Could some expert please guide me with very minimalistic code.
Also, I see that these properties are marked as not to be used in future, does anyone know what is it that replaces ?
Regards,
Indrajit

Efficient way to mark detected faces

I'm working on a small detection application using OpenCV and Qt.
my question is: what is the efficient way to mark the detected faces with rectangle knowing that I want this rectangles to be clickable in order to trigger some event for each clicked rectangle.
I've made this using a QPushButton ( with transparent background and some colored border) over a QLabel ( that contains the image ).
is there any other obvious way (maybe QSvg or QGraphicsView) ?
If you want to stick to widgets, then your current approach is the most obvious. If there can potentially be hundreds of faces, however, QGraphicsView would be more efficient, as it's designed for that.
If you can use Qt Quick, then using MouseArea and Rectangle within a Repeater would be the simplest approach. Exposing C++ code to QML is really simple, as well.

Removing arrows from scrollbar in Qt

I'm using a small black and white screen and need the scrollbar to just be a black slider in a black outer frame. I got what I wanted using style sheets but including them in the configuration when installing takes up too much space so I can't use them. Is it possible to remove the arrows by inheriting from QStyle or something?
thanks
You should create a subclass of a QStyle (or some subclass like QCommonStyle) and reimplement its drawComplexControl() function to paint CC_ScrollBar element by yourself.
Read QStyle's documentation for more.
This might be a dumb answer but would it help if you just specified the style sheet itself in code as a QString argument to setStyleSheet rather than maintain a separate file for it?
You can try to change palette settings for your scroll bar (according to designer scroll bar arrow color is "button text" color), but this approach looks lick little hack...
More "heavy" approach, is inherit from scroll bar widget and reimplement paint method, but there are it is looks like overkill...
So, you must choose little hack vs overkill :). Though maybe there are exist another solution

Resources