I am looking to create a digital Rolodex to keep track of contacts in Qt 5.9 and am uncertain how to efficiently create custom widgets. Examples online like the classic clock example show to completely override paint, but I want only to create a widget in design that is a collection of labels and buttons to display a list of contacts, and a few buttons to edit, delete, and create contacts beside it. The element entire arrangement appear multiple times across different parts of the application and it should look exactly the same in each.

enter image description here

I will have to create many other widgets just like this, so I am hoping to be able to drag-and-drop elements in designer rather than programmatically set everything.

Since each contact has its own little panel and picture, each contact is arranged in a scrolling list, and buttons are placed beside, we have:

  1. Create a ContactLabel custom widget with the picture, name, and address labels arranged
  2. Create a ContactsWidget custom widget with a Widget Listview containing a series of ContactLabel widgets, and buttons on the right.
  3. Wherever needed, drop the `contacts widget into a form.

It appears that visual studio addons and Qt Creator only want to create forms (which you can easily drop ui elements onto) or custom widgets, which only create code and do not automatically link in a ui file.

Is this an appropriate way to approach this problem and is there an easy way to drop in custom arrangements of controls?


You can "promote" a widget to your custom widget . The gist is you point the .ui file to a header file that defines your QWidget derived class, and the uic generated header uses that class.

However the visual look is that of the base widget (i.e. a blank frame for QWidget), and these are not added to the toolbox of widgets (you have to drop something else and promote it each time).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.