Skip to content
  • 0 Votes
    2 Posts
    406 Views
    B

    @tomendop see documentation for "Layout QML Type". It states:

    Note: It is not recommended to have bindings to the x, y, width, or height properties of items in a layout, since this would conflict with the goals of Layout, and can also cause binding loops.

    I can't say exactly what is going wrong in your example, but it is basically that you are doing something you aren't supposed to do when you choose to use the Layout mechanism.

    I think it can be quite confusing as QML has a number of different ways to manage layout and it isn't always obvious which way is best or most appropriate.

  • 0 Votes
    3 Posts
    1k Views
    L

    @jeremy_k

    Thank You for the explanation!

    As you said I had to implement the roleNames() Function and adjusted the data().

    The code below now works

    import sys import typing import PySide6 from PySide6 import QtCore from PySide6 import QtGui from PySide6.QtCore import QByteArray class ProductListModel (QtCore.QAbstractListModel): def __init__(self, products, parent = None): super().__init__(parent) self.products = products def data(self, index, role): """Returns an appropriate value for the requested data. If the view requests an invalid index, an invalid variant is returned. Any valid index that corresponds to a string in the list causes that string to be returned.""" row = index.row() if not index.isValid() or row >= len(self.products): return None product = self.products[row] if role == QtCore.Qt.DisplayRole: return product.name elif role == QtCore.Qt.EditRole: return product.name elif role == QtCore.Qt.UserRole + 1: return product.id elif role == QtCore.Qt.UserRole + 2: return product.name return None def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole): """Returns the appropriate header string depending on the orientation of the header and the section. If anything other than the display role is requested, we return an invalid variant.""" if role != QtCore.Qt.DisplayRole: return None if orientation == QtCore.Qt.Horizontal: return f"Column {section}" return f"Row {section}" def rowCount(self, parent: typing.Union[PySide6.QtCore.QModelIndex, PySide6.QtCore.QPersistentModelIndex] = ...) -> int: # return length of productList return len(self.products) def roleNames(self): roles = { QtCore.Qt.UserRole + 1: b'id', QtCore.Qt.UserRole + 2: b'name', } return roles class Product: def __init__(self, id:int, name:str): self.id = id self.name = name```
  • 0 Votes
    2 Posts
    295 Views
    SGaistS

    Hi,

    Please don't post the exact same question in multiple sub-forum. One is enough. When needed, it can be moved.

    Closing this one as duplicate from this thread since it's in the correct sub-forum.

  • 2 Votes
    13 Posts
    5k Views
    F

    @JohnKS Wow, I just spent like an hour trying to figure this out and copying detailed tutorials verbatim to try and get it working and it's this non-default flag that apparently doesn't always need to be set seeing as it doesn't appear anywhere in Qt's examples. It would be really helpful if this was mentioned more prominently somewhere.

  • 0 Votes
    4 Posts
    1k Views
    semlanikS

    @Kevin470
    The qt_standard_project_setup function doesn't set CMAKE_AUTORCC flag, only UIC and MOC. So you need to add:

    set(CMAKE_AUTORCC ON)

    before calling qt_add_executable.

  • Setting svg icon for TabButton

    Unsolved QML and Qt Quick
    7
    0 Votes
    7 Posts
    651 Views
    JoeCFDJ

    @Saviz I guess the path of the svg file may not be right. Can you post your qrc file here?
    do you use qmake or cmake?

    TabButton { id: root implicitHeight: *** implicitWidth: *** contentItem: Label { anchors.fill: parent Row { spacing: Image { id: buttonImage height: root.height width: root.height source:svg file } Text { text: root.text height: root.height width: root.availableWidth color: "white" horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter } } } }
  • 0 Votes
    3 Posts
    494 Views
    GrecKoG

    @JoeCFD Layouts are visual items...

  • 0 Votes
    1 Posts
    405 Views
    No one has replied
  • 0 Votes
    3 Posts
    301 Views
    A

    @ankou29666 That did not work too. Also, I do have a qrc path

  • QML grid & list Dynamic

    Unsolved QML and Qt Quick
    1
    0 Votes
    1 Posts
    117 Views
    No one has replied
  • 0 Votes
    2 Posts
    269 Views
    T

    Your code should be fine. I think that the console.log() command is just in the wrong place.

    If I understood correctly, there are two user interactions involved. The first one is the click on the mouse area, which opens the menu. The second one is a click on a particular menu item, which actually sets the test value.

    Let's say you are performing the first interaction for the first time. At this point, the variable hasn't been set as you haven't clicked on a menu item yet. That is why the output of the console.log() command will be undefined. Then, you click on a menu item, which sets the variable. However, you won't be able to see the change until the menu is closed and you perform another click on the mouse area to make the menu pop up again.

    I think you'll see that your code works if you move the console.log() command to a different place:

    id: mouseArea1 property var testValue; onClicked: { menu.popup(); } Menu { id: menu MenuItem { text: "Option1" onTriggered: { mouseArea1.testValue= "25"; console.log(mouseArea1.testValue); } } }

    I don't know how many menu items you have in your actual code. Doing it this way, you'd need to add the same line to the onTriggered() signal handlers on all MenuItem instances, which could be annoying and bloat your code unnecessarily. So I'd suggest doing this instead:

    id: mouseArea1 property var testValue; onClicked: { menu.popup(); } Menu { id: menu MenuItem { text: "Option1" onTriggered: { mouseArea1.testValue= "25"; } } onClosed: { console.log(mouseArea1.testValue); } }

    I am assuming that the menu is closed once you hit a menu item. The code above logs the variable once the menu emits a closed() signal. I haven't tried it myself, but it should work. :)

  • 0 Votes
    1 Posts
    290 Views
    No one has replied
  • 0 Votes
    3 Posts
    470 Views
    A

    @JoeCFD
    thank you so much for your reply. you save me from this problem.
    i solve this by removing other mingW compiler and it work properly.

  • 0 Votes
    4 Posts
    534 Views
    A

    I figure out this is because of Q_Object macro I added in those files.
    I don't know why the macro doesn't work maybe better open another post.
    in other posts people suggest to rerun the qmke to solve this problem but doesn't work for me
    anyone know why Q_Object macro doesn't work for android?

  • How create 3d CAD use QML

    Unsolved General and Desktop
    1
    0 Votes
    1 Posts
    236 Views
    No one has replied
  • 0 Votes
    12 Posts
    1k Views
    jeremy_kJ

    Defining a handler for a property change signal, and then setting a break point in that handler is my usual technique for finding unwanted changes.