跳到內容

QML and Qt Quick

Looking for The Bling Thing(tm)? Post here!
20.0k 主題 77.4k 貼文
  • Can I do this Animation in Qt

    Unsolved
    10
    0 評價
    10 貼文
    863 瀏覽
    ?
    @haiku Nice, thanks for sharing.
  • QML ListView and ListElement - initialization that is actually of use

    Unsolved
    3
    0 評價
    3 貼文
    1k 瀏覽
    B
    @VFCraig If I have understood correctly, an aspect of each delegate component in your list view is to show the current date and time. As you yourself allude to, the "current time" is a system-wide thing and I can't really see any benefit in trying to do this via the model. I would suggest that a better way to think about is that your delegate makes use of a visual component that displays the current date and time and that this is independent from the parts of the delegate that genuinely depend on the model (i.e. the data that is specific to the current item in the list).
  • Show column titles in HorizontalHeaderView

    Unsolved
    4
    0 評價
    4 貼文
    1k 瀏覽
    fcarneyF
    The docs don't show it specifying a model. Not sure what is supposed to happen with headerData. I don't know how to build the delegate for a qabstracttablemodel. I just read the docs and figure things out. Edit: This might help. https://stackoverflow.com/questions/63719365/horizontalheaderview-not-calling-headerdata-of-qabstracttablemodels-child
  • Adding a "ui" to an empty Project template

    Solved
    2
    0 評價
    2 貼文
    273 瀏覽
    D
    It seems that this is some sort of GUI Issue under Qt6 with linux. I reinstalled QtCreator and used Qt 5.12 and now when i switch to the Designer in an empty project i can see a "canvas" and put components on it. So its solved for me.
  • CPU usage spike in qml charts

    Unsolved
    1
    0 評價
    1 貼文
    159 瀏覽
    尚無回覆
  • QML ListModel: remove: indices out of range

    4
    0 評價
    4 貼文
    1k 瀏覽
    B
    If the requirement is, as you say, simply to output the selections, the simplest way might be to clear the output list and rebuild it every time a selection is changed. Then you just need to loop over the combo list and add the items that are selected. I have noticed that you are not storing the check state in your combo model. You would need to do this to implement what I just suggested, but in any case I think you can't rely on the delegate to store the checked state. You might get away with it here, but in general, and especially if you had a longer list in your combo, delegates can get "recycled" in the view so you cannot rely on them holding any state.
  • Proper access of buttons from ButtonGroup?

    Solved
    2
    0 評價
    2 貼文
    396 瀏覽
    eyllanescE
    @robro Use ButtonGroup { id: btnGroup onClicked: function(button) { console.log("clicked:", button.text); } }
  • ListView, ListModel and ListElement and trying very hard not to hard code, which would make it worthless

    Unsolved
    5
    0 評價
    5 貼文
    509 瀏覽
    B
    @VFCraig Ok, I see what you are saying, but you have a very specific use case there, where your delegates simply create a button. It's not unusual in ListView instances to define more complex delegates with two or more items in some sort of layout. In such cases, there isn't such a simple initialisation as each delegate item will pick out whatever model data it needs. Additionally, it is not unusual not to bind the data directly to delegate properties but instead to bind to expressions involving the model data.
  • Qt Quick Emulation Layer Crashed

    Unsolved
    1
    0 評價
    1 貼文
    163 瀏覽
    尚無回覆
  • What is the right way to use theme colors?

    Unsolved
    1
    0 評價
    1 貼文
    128 瀏覽
    尚無回覆
  • Slider is not a type

    Unsolved
    8
    1 評價
    8 貼文
    838 瀏覽
    B
    @kgregory I had exactly the same problem (with many different types) moving from 5.7 to 5.15 AND the same solution (to "downgrade" the import to statement from say, "QtQtuick.Controls 2.2" to "QtQuick.Controls 2.15"). I'm concerned that the solution is more specific, because it just seems weird. Unfortunately the QML I'm migrating was written by a real QML expert, and I'm having trouble knowing with confidence that I'm understanding all the subtleties involved. Here's an example: import QtQuick 2.7 import QtQuick.Controls 2.2 as QtControls import bacon 1.0 import bacon.controls 2.0 import bacon.theme 1.0 QtControls.ScrollView { id: root property bool frameVisible: false property alias vertical: vbar property alias horizontal: hbar clip: true padding: root.frameVisible ? Theme.getMetric('scrollbar-frame-breadth') : 0 background: Rectangle { border { color: Theme.getColor(root.activeFocus ? 'accent' : 'secondary') width: root.padding } color: 'transparent' } QtControls.ScrollBar.vertical: ScrollBar { id: vbar parent: root x: root.mirrored ? root.rightPadding : root.width - width - root.rightPadding y: root.topPadding height: root.availableHeight active: hbar.active minimumSize: Theme.getMetric('scrollbar-minimum-height') / availableHeight } QtControls.ScrollBar.horizontal: ScrollBar { id: hbar parent: root x: root.leftPadding y: root.height - height - root.bottomPadding width: root.availableWidth - (vbar.visible ? vbar.width : 0) active: vbar.active minimumSize: Theme.getMetric('scrollbar-minimum-width') / availableWidth } } The problem is that the line number of the error refers to the alias above, which includes two references to "ScrollBar" (the thing the error says is not a type). Fortunately includes the column which includes, which suggests that it is the second reference. Anyway, like you, it makes me nervous to simply change the import from 2.2 to 2.15 even if in some cases it fixes the problem. One possibility is that the QML has never been technically correct, but that older QML compiler was more tolerant of some error and importing the import QtQuick.Controls 2.2 directive implies a more strict language policy. @AndyS My example is the whole file, but of course it doesn't include all the customization that went into our control versions. There really is an issue here.
  • QML framework Bug found , text Area and Markdown, garbage remain after emptying content

    Unsolved
    1
    1 評價
    1 貼文
    261 瀏覽
    尚無回覆
  • Is it possible to change space size between elemets of a Tumbler inside eponymous class?

    Unsolved
    3
    1 評價
    3 貼文
    276 瀏覽
    C
    @JonB, actually, I had to google the word after using it because I was not sure in doing it correctly :)
  • Create DelegateChooser from JavaScript dynamically. How?

    已移動 Unsolved
    1
    0 評價
    1 貼文
    146 瀏覽
    尚無回覆
  • Hide text area from SpinBox

    Unsolved
    4
    0 評價
    4 貼文
    493 瀏覽
    S
    @Bob64 Yeah, that documentation is helpful. Thanks. I was able to hide the text box now by using contentItem. Thanks
  • QML TextArea, process each character one at a time during input/typing

    Unsolved
    2
    0 評價
    2 貼文
    878 瀏覽
    jeremy_kJ
    @cebuger said in QML TextArea, process each character one at a time during input/typing: I have a text area (in QML) and i want to listen to every characters inputted on it, What i am trying to do is when a spacebar is pressed, I will perform an operation or processing such as replacing some characters on it. I have tried and listen to onTextChanged however, it may cause recursion as setting my TextArea.text to new value triggers a call to onTextChange event thus causing stack overflow. If monitoring textChanged is the route you want to go, recursion can be avoided through the use of a flag. Eg TextArea { property bool editing: false onTextChanged: { if (editing) return; editing = true; text += "something"; editing = false; } } I have tried to listen to Keys.onPressed event as well and listen to space key but the space key is processed as well and when i set a new text value, the space value is forcedly inserted. How and where should i handled and listen to these events? An code sample would make it easier to offer relevant commentary. Both QtQuick.Controls 1 and QtQuick.Controls 2 have a TextArea, with different interfaces. (1) How can i listen to each inputted characters in QML text area, catch the space bar, process and replace the text with the new processed text? also ignore the last spacebar entry? (2) how do i reject a chracter when inputted in the TextEdit or TextArea? say for example, i want to prevent spacebar input in summary this is what i need in pseudocode something input event per character :{ if(input is spacebar) { var newtext = processText(myTextArea.text); // process the text without the last space .. myTextArea.text = newText + " "; // append the space } } import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls 2.15 Window { TextArea { anchors.fill: parent Keys.onSpacePressed: { var pre = text.slice(0, cursorPosition); var post = text.slice(cursorPosition); text = pre + "<space>" + post; cursorPosition = pre.length + "<space>".length; } } }
  • Enter key to accept dialog

    Unsolved
    4
    0 評價
    4 貼文
    2k 瀏覽
    B
    @Mr-MinimalEffort I tried out your example. It is a good example of implementing keyboard navigation between fields but I don't think I explained very well because, whereas in a sense it goes further than what I was asking about, it does not do the main thing I am interested in which is how to implement behaviour such that dialogs may be accepted (i.e. equivalent of pressing "Ok") by pressing return/enter on keyboard. This is supported out of the box in QtWidgets by the concept of a 'default' button. Here's an example from Visual Studio on Windows, the Tools...|Options dialog: [image: 734bf196-b66f-4bee-ab30-ac1649ddfe09.png] As you can see, the OK button is highlighted here to indicate that it is the default button. No matter how much I click around in the dialog, I can at any point press my return key to accept the dialog. Here's some example code with three dialogs: the one you provided, a simple message dialog with the most basic out of the box implementation, and a modified version of the latter that does what I want it to but I don't know if this is the right way to do it. I haven't posted it yet, but the next one would have a single combo widget which causes more complication because it can take focus away from the buttons. However, it would be good to understand the options for the most basic case before getting into that. (BTW I am, for work reasons, unfortunately still on 5.9.6.) import QtQuick 2.9 import QtQuick.Window 2.2 import QtQuick.Controls 2.2 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Dialog { id: dialog1 title: "My Dialog" x: (parent.width - width)/2 y: (parent.height - height)/2 focus: true Column { anchors.fill: parent Text { text: "Here is my Dialog" } TextField { id: textInput placeholderText: "Input some text" KeyNavigation.tab: textInput2 } TextField { id: textInput2 placeholderText: "Input some text" KeyNavigation.backtab: textInput KeyNavigation.tab: textInput3 } TextField { id: textInput3 placeholderText: "Input some text" KeyNavigation.backtab: textInput2 KeyNavigation.tab: textInput Keys.onReturnPressed: dialog.accept() } Row { Button { id: cancelButton text: "Cancel" onClicked: dialog.reject() } Button { id: okButton text: "Ok" onClicked: dialog.accept() } } } onAccepted: { console.log("Accepted") } onRejected: { console.log("Rejected") } onOpened: { textInput.focus = true } } Dialog { id: dialog2 height: 150; width: 150 x: (parent.width - width) / 2 y: (parent.height - height) / 2 focus: true modal: true Label { verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter anchors.centerIn: parent text: "Hello" } standardButtons: Dialog.Ok } Dialog { id: dialog3 height: 150; width: 150 x: (parent.width - width) / 2 y: (parent.height - height) / 2 focus: true modal: true Label { verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter anchors.centerIn: parent text: "Hello" } standardButtons: Dialog.Ok footer: DialogButtonBox { id: buttons standardButtons: Dialog.Ok alignment: Qt.AlignHCenter Keys.onEnterPressed: dialog3.accept() Keys.onReturnPressed: dialog3.accept() onVisibleChanged: if (visible) forceActiveFocus() } } Column { anchors.top: parent.top anchors.left: parent.left anchors.margins: 5 spacing: 5 Button { text: "Open dialog 1" onClicked: dialog1.open() } Button { text: "Open dialog 2" onClicked: dialog2.open() } Button { text: "Open dialog 3" onClicked: dialog3.open() } } }
  • Auto format Markdown text in QML textarea/text edit

    Unsolved
    1
    1 評價
    1 貼文
    331 瀏覽
    尚無回覆
  • How to open files with QFileDialog or something?

    Unsolved
    3
    0 評價
    3 貼文
    424 瀏覽
    B
    As far as I know there is no direct way to read file content from QML, so some sort of C++ extension is needed, as indicated by @Dannick-Stark. This StackOverflow answer describes an approach that exposes a "FileIO" object to QML from C++.
  • How to know which line the specified position is in the TextArea

    Unsolved
    2
    0 評價
    2 貼文
    238 瀏覽
    D
    You can try to get the whole text from the start to the position of the cursor. Then split it into a list of lines and return the length of the list. function currentLine(){ let list = text.text.substring(0, text.cursorPosition).split(/\n/gm) return list.length }