(Difference between revisions)

Archived:How to clone user interface objects and inheriting common properties in Qt

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
Line 34: Line 34:
==Source Code==
==Source Code==
<code cpp>
<code cpp-qt>
#include <QtGui/QApplication>
#include <QtGui/QApplication>
#include "list.h"
#include "list.h"

Latest revision as of 04:14, 11 October 2012

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.

Article Metadata
Tested with
Devices(s): S60 Emulator
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
Keywords: QListWidget,clone(),QListWidgetItem
Created: mind_freak (13 Jul 2009)
Last edited: hamishwillee (11 Oct 2012)

[edit] Overview

Sometimes we want to build many user interface widgets that share common properties, for example: same font type, same icons, same colors, etc. In such cases, we can create the "template object" first and after that use the clone() method to create copies that have all the properties set up first.

[edit] Source Code

#include <QtGui/QApplication>
#include "list.h"
int main(int argc, char *argv[])
QApplication a(argc, argv);
QListWidget listWidget;
QListWidgetItem * patt = new QListWidgetItem(this); // Making the initial pattern
QListWidgetItem * name = patt->clone(); // cloning of pattern
listWidget.insertItem(0, name);
name = patt->clone(); // cloning of pattern
listWidget.insertItem(0, name);
name = patt;
name->setText("OT for S60");
listWidget.insertItem(0, name);
return a.exec();
This page was last modified on 11 October 2012, at 04:14.
63 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.