#include <QApplication>
#include <QWidget>
#include <QLabel>
#include <QComboBox>
#include <QVBoxLayout>
#include <QCommandLineParser>
#include <QCommandLineOption>
int main(int argc, char *argv[])
{
QCommandLineParser parser;
parser.setApplicationDescription("A test to observe memory usage of QIcon.");
parser.addHelpOption();
QCommandLineOption useIconOption
(QStringList() <<
"i" <<
"icon",
"Use the QIcon constructor");
parser.addOption(useIconOption);
QCommandLineOption usePixmapOption
(QStringList() <<
"p" <<
"pixmap",
"Use the QPixmap constructor");
parser.addOption(usePixmapOption);
parser.process(a);
bool useIcon = parser.isSet(useIconOption);
bool usePixmap = parser.isSet(usePixmapOption);
if(useIcon)
{
layout
->addWidget
(new QLabel("Using Icon Contructor"));
}
else if(usePixmap)
{
layout
->addWidget
(new QLabel("Using Pixmap Contructor"));
}
for(int i = 0; i < 20; ++i)
{
if(useIcon)
{
box
->addItem
(QIcon(":/img/about-icon.png"),
QObject::tr("Box %1 - 1").
arg(i
));
box
->addItem
(QIcon(":/img/android-add-contact.png"),
QObject::tr("Box %1 - 2").
arg(i
));
box
->addItem
(QIcon(":/img/Bug.png"),
QObject::tr("Box %1 - 3").
arg(i
));
box
->addItem
(QIcon(":/img/database-symbol-md.png"),
QObject::tr("Box %1 - 4").
arg(i
));
box
->addItem
(QIcon(":/img/Devices-printer-icon.png"),
QObject::tr("Box %1 - 5").
arg(i
));
}
else if(usePixmap)
{
box
->addItem
(QIcon(QPixmap(":/img/android-add-contact.png")),
QObject::tr("Box %1 - 2").
arg(i
));
box
->addItem
(QIcon(QPixmap(":/img/database-symbol-md.png")),
QObject::tr("Box %1 - 4").
arg(i
));
box
->addItem
(QIcon(QPixmap(":/img/Devices-printer-icon.png")),
QObject::tr("Box %1 - 5").
arg(i
));
}
else
{
box
->addItem
(QObject::tr("Box %1 - 1").
arg(i
));
box
->addItem
(QObject::tr("Box %1 - 2").
arg(i
));
box
->addItem
(QObject::tr("Box %1 - 3").
arg(i
));
box
->addItem
(QObject::tr("Box %1 - 4").
arg(i
));
box
->addItem
(QObject::tr("Box %1 - 5").
arg(i
));
}
layout->addWidget(box);
}
mainWidget.setLayout(layout);
mainWidget.show();
return a.exec();
}
#include <QApplication>
#include <QWidget>
#include <QLabel>
#include <QComboBox>
#include <QVBoxLayout>
#include <QCommandLineParser>
#include <QCommandLineOption>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCommandLineParser parser;
parser.setApplicationDescription("A test to observe memory usage of QIcon.");
parser.addHelpOption();
QCommandLineOption useIconOption(QStringList() << "i" << "icon", "Use the QIcon constructor");
parser.addOption(useIconOption);
QCommandLineOption usePixmapOption(QStringList() << "p" << "pixmap", "Use the QPixmap constructor");
parser.addOption(usePixmapOption);
parser.process(a);
bool useIcon = parser.isSet(useIconOption);
bool usePixmap = parser.isSet(usePixmapOption);
QWidget mainWidget;
QVBoxLayout *layout = new QVBoxLayout;
if(useIcon)
{
layout->addWidget(new QLabel("Using Icon Contructor"));
}
else if(usePixmap)
{
layout->addWidget(new QLabel("Using Pixmap Contructor"));
}
for(int i = 0; i < 20; ++i)
{
QComboBox *box = new QComboBox;
box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
if(useIcon)
{
box->addItem(QIcon(":/img/about-icon.png"), QObject::tr("Box %1 - 1").arg(i));
box->addItem(QIcon(":/img/android-add-contact.png"), QObject::tr("Box %1 - 2").arg(i));
box->addItem(QIcon(":/img/Bug.png"), QObject::tr("Box %1 - 3").arg(i));
box->addItem(QIcon(":/img/database-symbol-md.png"), QObject::tr("Box %1 - 4").arg(i));
box->addItem(QIcon(":/img/Devices-printer-icon.png"), QObject::tr("Box %1 - 5").arg(i));
}
else if(usePixmap)
{
box->addItem(QIcon(QPixmap(":/img/about-icon.png")), QObject::tr("Box %1 - 1").arg(i));
box->addItem(QIcon(QPixmap(":/img/android-add-contact.png")), QObject::tr("Box %1 - 2").arg(i));
box->addItem(QIcon(QPixmap(":/img/Bug.png")), QObject::tr("Box %1 - 3").arg(i));
box->addItem(QIcon(QPixmap(":/img/database-symbol-md.png")), QObject::tr("Box %1 - 4").arg(i));
box->addItem(QIcon(QPixmap(":/img/Devices-printer-icon.png")), QObject::tr("Box %1 - 5").arg(i));
}
else
{
box->addItem(QObject::tr("Box %1 - 1").arg(i));
box->addItem(QObject::tr("Box %1 - 2").arg(i));
box->addItem(QObject::tr("Box %1 - 3").arg(i));
box->addItem(QObject::tr("Box %1 - 4").arg(i));
box->addItem(QObject::tr("Box %1 - 5").arg(i));
}
layout->addWidget(box);
}
mainWidget.setLayout(layout);
mainWidget.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks