QWidgetFactory(3qt)

πŸ“¦ version 3.3.8b, in fedora 43, fedora 44

✨ QWidgetFactory ✨ (that's the qwidgetfactory.3qt manual page bestie, section 3qt)

okay so real talk: QWidgetFactory is giving dynamic widget creation from Qt Designer .ui files and honestly? iconic. Let's get into it πŸŽ€


🌸 SYNOPSIS 🌸

#include <qwidgetfactory.h>

πŸ’– Public Members

QWidgetFactory ()
virtual ~QWidgetFactory ()
virtual QWidget * createWidget ( const QString & className, QWidget *
    parent, const char * name ) const

⭐ Static Public Members

QWidget * create ( const QString & uiFile, QObject * connector = 0,
    QWidget * parent = 0, const char * name = 0 )
QWidget * create ( QIODevice * dev, QObject * connector = 0, QWidget *
    parent = 0, const char * name = 0 )
void addWidgetFactory ( QWidgetFactory * factory )
void loadImages ( const QString & dir )
QStringList widgets ()
bool supportsWidget ( const QString & widget )

πŸ¦‹ DESCRIPTION πŸ¦‹

So QWidgetFactory is the class that handles the dynamic creation of widgets from Qt Designer .ui files. no cap.

It's basically serving two things, and both of them ate:

  • Dynamically creating widgets from Qt Designer user interface description files. You do this with the static function QWidgetFactory::create(). That function is also out here doing signal and slot connections, tab ordering, etc., exactly as defined in the .ui file, and it hands you back the top-level widget in the .ui file. Once you've got that widget, you can use QObject::child() and QObject::queryList() to get at the child widgets of the returned widget. πŸ’…
  • Adding extra widget factories so you can create custom widgets. See createWidget() for the deets.
⚠️ Heads up bestie: this class is not included in the Qt library itself. To use it you must link against libqui.so (Unix) or qui.lib (Windows), which gets built into INSTALL/lib if you built Qt Designer (where INSTALL is the directory where Qt is installed).

If you create a QMainWindow using a QWidgetFactory, be aware it already has a central widget. So you need to delete that one before setting another one. periodt.

See the "Creating Dynamic Dialogs from .ui Files" section of the Qt Designer manual for an example. Also peep the QWidgetPlugin class and the Plugins documentation. 🌈


πŸ‘‘ MEMBER FUNCTION DOCUMENTATION πŸ‘‘

QWidgetFactory::QWidgetFactory ()

Constructs a QWidgetFactory. new toy just dropped ✨

QWidgetFactory::~QWidgetFactory () [virtual]

Destructor. it's giving goodbye 😭

void QWidgetFactory::addWidgetFactory ( QWidgetFactory * factory ) [static]

Installs a widget factory factory, which normally contains additional widgets that can then be created using a QWidgetFactory. See createWidget() for further details. slay 🫢

QWidget * QWidgetFactory::create ( const QString & uiFile, QObject * connector = 0, QWidget * parent = 0, const char * name = 0 ) [static]

Loads the Qt Designer user interface description file uiFile and returns the top-level widget in that description. parent and name get passed to the constructor of the top-level widget.

This function also does signal and slot connections, tab ordering, etc., as described in the .ui file. Here's the tea: in Qt Designer you can add custom slots to a form and connect to them. If you want those connections to actually be made, you must create a class derived from QObject that implements all these slots. Then pass an instance of that object as connector to this function. If you do that, the connections to the custom slots will be done using the connector as slot. πŸŽ€

If something fails, 0 is returned.

The ownership of the returned widget is passed to the caller.

QWidget * QWidgetFactory::create ( QIODevice * dev, QObject * connector = 0, QWidget * parent = 0, const char * name = 0 ) [static]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Loads the user interface description from device dev. same vibe, different input πŸ’…

QWidget * QWidgetFactory::createWidget ( const QString & className, QWidget * parent, const char * name ) const [virtual]

Creates a widget of the type className, passing parent and name to its constructor.

If className is a widget in the Qt library, it's directly created by this function. If the widget isn't in the Qt library, then each of the installed widget plugins gets asked, in turn, to create the widget. As soon as a plugin says it can create the widget, it's asked to do so. It may occur that none of the plugins can create the widget, in which case each installed widget factory is asked to create the widget (see addWidgetFactory()). And if the widget cannot be created by any of these means, 0 is returned. πŸ’€

If you have a custom widget and want it created using the widget factory, there are two approaches you can use:

  1. Write a widget plugin. This allows you to use the widget in Qt Designer and in this QWidgetFactory. See the widget plugin documentation for further details. (See the "Creating Custom Widgets with Plugins" section of the Qt Designer manual for an example.
  2. Subclass QWidgetFactory. Then reimplement this function to create and return an instance of your custom widget if className equals the name of your widget, otherwise return 0. Then at the beginning of your program where you want to use the widget factory to create widgets, do a:
QWidgetFactory::addWidgetFactory( new MyWidgetFactory );

where MyWidgetFactory is your QWidgetFactory subclass.

void QWidgetFactory::loadImages ( const QString & dir ) [static]

If you use a pixmap collection (which is the default for new projects) rather than saving the pixmaps within the .ui XML file, you must load the pixmap collection. QWidgetFactory looks in the default QMimeSourceFactory for the pixmaps. Either add it there manually, or call this function and specify the directory where the images can be found, as dir. This is normally the directory called images in the project's directory. πŸ–ΌοΈβœ¨

bool QWidgetFactory::supportsWidget ( const QString & widget ) [static]

Returns TRUE if the widget factory can create the specified widget; otherwise returns FALSE. simple as that bestie πŸ“

QStringList QWidgetFactory::widgets () [static]

Returns the names of the widgets this factory can create. the roster, if you will πŸ‘‘


🌟 SEE ALSO 🌟


Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.

🧚 AUTHOR 🧚

Generated automatically from the source code.

πŸ™ˆ BUGS πŸ™ˆ

If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. 🫢

The definitive Qt documentation is provided in HTML format; it's located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech.

If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qwidgetfactory.3qt) and the Qt version (3.3.8).


and that's the whole thing, bestie πŸ’… Trolltech AS β€” 2 February 2007 β€” QWidgetFactory(3qt) β€” go forth and dynamically create widgets, you've got this πŸŽ€πŸ’–

πŸ“¦ where this page comes from