Namespaces
Variants
Actions

Archived:How to add an icon to a QPushButton

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.

This (archived) code snippet demonstrates how to add icons to buttons in QWidget based applications.

Article Metadata

Tested with
Devices(s): Emulator

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

Platform Security
Signing Required: Self-Signed
Capabilities: None

Article
Keywords: QIcon, QPushButton
Created: james1980 (09 Jan 2009)
Last edited: hamishwillee (11 Oct 2012)

Main Function

  • Function to set Icon
 button->setIcon(QIcon("c://butterfly.png"));

QIcon property holds the icon shown on the button. The icon's default size is defined by the GUI style, but can be adjusted by setting the iconSize property.

Source File

#include <QApplication>
#include <QPushButton>
#include <QWidget>
#include <QHBoxLayout>
#include <QIcon>
 
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
 
QWidget *win = new QWidget;
QHBoxLayout *layout = new QHBoxLayout;
QPushButton *button = new QPushButton;
 
button->setIcon(QIcon("c://butterfly.png"));
 
QPushButton *button1 = new QPushButton;
button1->setIcon(QIcon("c://savebutton.png"));
QPushButton *button2 = new QPushButton;
button2->setIcon(QIcon("c://exitbutton.png"));
layout->addWidget(button);
layout->addWidget(button1);
layout->addWidget(button2);
 
win->setLayout(layout);
win->showMaximized();
return app.exec();
}

Screenshot

Qticon.png

This page was last modified on 11 October 2012, at 04:14.
473 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