Difference between revisions of "Qt/Icons"
From ProgrammingExamples
< Qt
Daviddoria (Talk | contribs) (Created page with '==Style.cpp== <source lang="cpp"> #include <QApplication> #include "form.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); Form form; form.show(); …') |
(No difference)
|
Latest revision as of 20:13, 7 June 2011
Style.cpp
#include <QApplication> #include "form.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); Form form; form.show(); return app.exec(); }
form.h
#ifndef FORM_H #define FORM_H #include "ui_form.h" #include <QMainWindow> class Form : public QMainWindow, private Ui::MainWindow { Q_OBJECT public: Form(QWidget *parent = 0); public slots: }; #endif
form.cpp
#include <QtGui> #include "form.h" Form::Form(QWidget *parent) : QMainWindow(parent) { setupUi(this); QCommonStyle* myStyle = new QCommonStyle; QIcon openIcon = myStyle->standardIcon(QStyle::SP_DriveCDIcon ); QAction* openAction = new QAction(openIcon, "&Open...", this); toolBar->addAction(openAction); }
form.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionSave"/>
</widget>
<addaction name="menuFile"/>
</widget>
<widget class="QToolBar" name="toolBar">
<property name="enabled">
<bool>true</bool>
</property>
<property name="windowTitle">
<string>toolBar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionSave"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="actionSave">
<property name="icon">
<iconset>
<normaloff>:/home/doriad/Desktop/button.png</normaloff>
<normalon>:/images/button.png</normalon>:/home/doriad/Desktop/button.png</iconset>
</property>
<property name="text">
<string>Save</string>
</property>
</action>
</widget>
<resources>
<include location="menu.qrc"/>
</resources>
<connections/>
</ui>CMakeLists.txt
cmake_minimum_required(VERSION 2.6) PROJECT(Style) FIND_PACKAGE(Qt4 REQUIRED) INCLUDE(${QT_USE_FILE}) QT4_WRAP_UI(Toolbar_UI form.ui) QT4_WRAP_CPP(Toolbar_MOC form.h) include_directories(${include_directories} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) ADD_EXECUTABLE(Style Style.cpp form.h form.cpp ${Toolbar_UI} ${Toolbar_MOC}) TARGET_LINK_LIBRARIES(Style ${QT_LIBRARIES})