qt - MouseArea covering a QML Row (or, Auto-Sizing Image+Text) -
summary: how can stick icon next text, without hardcoding dimensions, , wrap both of them in mousearea
...in way works inside gridlayout
?
i have created qml layout has rows of labels across tappable "buttons". buttons icon along text:
to create buttons using row
, 2 items stick (without hardcoded dimensions) , have automatic size gridlayout
can use:
gridlayout { columns:2; rowspacing:30 text { text: audioserver.label layout.alignment: qt.alignleft } row { spacing:10; layout.alignment:qt.alignright image { width:29; height:30; y:10; source:"qrc:/rescan.png" } text { text:"find another" } } text { text: "system uptime "+system.uptime layout.alignment: qt.alignleft } row { spacing:10; layout.alignment:qt.alignright image { width:29; height:30; y:10; source:"qrc:/restart.png" } text { text: "restart" } } }
i want put mousearea
around each button. if put inside row, this...
row { image { width:29; height:30; y:10; source:"qrc:/rescan.png" } text { text:"find another" } mousearea { anchors.fill: parent onclicked: rescan() } }
...then (reasonable) error qml row: cannot specify left, right, horizontalcenter, fill or centerin anchors items inside row. row not function.
and, more importantly, layout breaks (i think row gets 0 width, gridlayout has flow off right side.)
i cannot move mousearea
outside of gridlayout
this...
gridlayout { ... row { id: rescanbutton image { width:29; height:30; y:10; source:"qrc:/rescan.png" } text { text:"find another" } } } mousearea { anchors.fill: rescanbutton onclicked: rescan() }
...because can anchor siblings or parents.
but cannot put mousearea
inside gridlayout
, because try lay out item.
how can mousearea wrapping buttons?
it's acceptable me use container other row
, prefer not hard-code text or container dimensions.
with have got this:
gridlayout { ... mousearea { onclicked: rescan() width: childrenrect.width height: childrenrect.height row { image { width:29; height:30; y:10; source:"qrc:/rescan.png" } text { text:"find another" } } } }