[Interest] Writing custom Qt Widgets is overly complicated

Federico Ferri federico.ferri.it at gmail.com
Tue Apr 28 14:17:12 CEST 2020


On 28 April 2020 at 12:05:54, Jonathan Purol (contact at folling.de) wrote:

Yesterday however I put my hands on trying to implement my first custom
widget.

The item in question is what I would describe as a "Tag Textfield".

[…]

The last approach seemed rather clever, and it worked pretty well. I could
put widgets into the textfield and align them at the left. First I tried to
do this manually, then I opted for an HBoxLayout.


Sorry, I don’t really have a solution for Qt Widgets. But is QHBoxLayout
really the best pick there? I would go for a “flow” layout, like the QML
‘Flow’ positioner (but you’d have to make it yourself). In this way your
tags can wrap correctly according to widget’s width.


In fact this is what I did in my QML Tag Edit widget (
https://github.com/fferri/QtQuick-TagsEditItem) maybe this is the shoddy
one you said you already found :-D

I didn’t put too much effort in it, and it has some minor issues, as it can
be seen from the screenshot. But the implementation is very simple, so one
can easily pick up from that and extend it. Maybe also fixing those
positioning issues is a one-liner fix (if anyone wants to contribute a fix…
PRs are welcome).


Maybe you can copy and adapt the implementation to Qt Widgets.


Cheers,

Federico Ferri
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200428/6a3acd5e/attachment.html>


More information about the Interest mailing list