Namespaces
Variants
Actions

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

Jump to: navigation, search
Archived.png
Archived: 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

Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition

Article
Keywords: QListWidget,clone(),QListWidgetItem
Created: mind_freak (13 Jul 2009)
Last edited: hamishwillee (11 Oct 2012)

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.

Source Code

#include <QtGui/QApplication>
#include "list.h"
#include<QListWidget>
#include<QListWidgetItem>
 
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QListWidget listWidget;
 
QListWidgetItem * patt = new QListWidgetItem(this); // Making the initial pattern
patt->setFont(QFont("Times"));
patt->setTextColor(Qt::blue);
patt->setBackgroundColor(Qt::yellow);
 
QListWidgetItem * name = patt->clone(); // cloning of pattern
name->setText("N97");
listWidget.insertItem(0, name);
 
name = patt->clone(); // cloning of pattern
name->setText("Nokia");
listWidget.insertItem(0, name);
 
name = patt;
name->setText("OT for S60");
listWidget.insertItem(0, name);
 
listWidget.sortItems();
listWidget.show();
return a.exec();
}
This page was last modified on 11 October 2012, at 04:14.
228 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved