Time for action – making the button a reusable component

So far, we have been working on a single button. Adding another button by copying the code, changing the identifiers of all components, and setting different bindings to properties are very tedious tasks. Instead, we can make our button item a real component, that is, a new QML type that can be instantiated on demand as many times as required.

First, position the text cursor right before the bracket opening of the definition of the button and press Alt + Enter on the keyboard to open the refactoring menu, like in the following screenshot:

Time for action – making the button a reusable component

From the menu, choose Move Component into Separate File ...

Get Game Programming Using Qt now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.