How to create alarm list in Qt
hamishwillee
(Talk | contribs) m (Hamishwillee - Subedit - rearrange to make it obvious that this is a "layout" example, not really an alarms example.) |
hamishwillee
(Talk | contribs) m (Text replace - "<code cpp>" to "<code cpp-qt>") |
||
| (4 intermediate revisions by one user not shown) | |||
| Line 1: | Line 1: | ||
[[Category:Qt]] | [[Category:Qt]] | ||
| − | {{ArticleMetaData | + | {{ArticleMetaData <!-- v1.2 --> |
| − | |sourcecode=[[Media:Alarmlist.zip]] | + | |sourcecode= [[Media:Alarmlist.zip]] |
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | |installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | ||
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') --> | |devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') --> | ||
| − | |sdk=[[ | + | |sdk= [[Qt SDK]] |
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later --> | |platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later --> | ||
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) --> | |devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) --> | ||
| − | |dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> | + | |dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> |
| − | |signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer --> | + | |signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer --> |
| − | |capabilities=<!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. --> | + | |capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. --> |
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase --> | |keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase --> | ||
| − | + | |language= <!-- Language category code for non-English topics - e.g. Lang-Chinese --> | |
| − | |language=<!-- Language category code for non-English topics - e.g. Lang-Chinese --> | + | |translated-by= <!-- [[User:XXXX]] --> |
| − | |review-by=<!-- After re-review: [[User:username]] --> | + | |translated-from-title= <!-- Title only --> |
| − | |review-timestamp=<!-- After re-review: YYYYMMDD --> | + | |translated-from-id= <!-- Id of translated revision --> |
| − | |update-by=<!-- After significant update: [[User:username]]--> | + | |review-by= <!-- After re-review: [[User:username]] --> |
| − | |update-timestamp=<!-- After significant update: YYYYMMDD --> | + | |review-timestamp= <!-- After re-review: YYYYMMDD --> |
| − | |creationdate=20100406 | + | |update-by= <!-- After significant update: [[User:username]]--> |
| − | |author=[[User:Rahulvala]] | + | |update-timestamp= <!-- After significant update: YYYYMMDD --> |
| + | |creationdate= 20100406 | ||
| + | |author= [[User:Rahulvala]] | ||
}} | }} | ||
{{Abstract|This code example shows shows how to layout a number of {{Icode|QWidgets}} in a {{Icode|MainWindow}} application, including {{Icode|QLabel}}, {{Icode|QCheckBox}}, and {{Icode|QTimeEdit}}. The {{Icode|QCheckBox}} and {{Icode|QTimeEdit}} are connected using '''signal and slot''' mechanism. The code is the UI layer for an "alarm" application - however the actual alarm code is not included.}} | {{Abstract|This code example shows shows how to layout a number of {{Icode|QWidgets}} in a {{Icode|MainWindow}} application, including {{Icode|QLabel}}, {{Icode|QCheckBox}}, and {{Icode|QTimeEdit}}. The {{Icode|QCheckBox}} and {{Icode|QTimeEdit}} are connected using '''signal and slot''' mechanism. The code is the UI layer for an "alarm" application - however the actual alarm code is not included.}} | ||
| + | {{Warning|The article title is deceptive - this doesn't actually show how to set alarms. It demonstrates how to layout a basic UI using QWidgets}} | ||
[[File:outputalarm.jpg]] | [[File:outputalarm.jpg]] | ||
==Header file== | ==Header file== | ||
| − | <code cpp> | + | <code cpp-qt> |
#ifndef MAINWINDOW_H | #ifndef MAINWINDOW_H | ||
#define MAINWINDOW_H | #define MAINWINDOW_H | ||
| Line 52: | Line 55: | ||
==Source file== | ==Source file== | ||
| − | <code cpp> | + | <code cpp-qt> |
#include "mainwindow.h" | #include "mainwindow.h" | ||
#include "ui_mainwindow.h" | #include "ui_mainwindow.h" | ||
| Line 85: | Line 88: | ||
==ui_mainwindow.cpp== | ==ui_mainwindow.cpp== | ||
| − | <code cpp> | + | <code cpp-qt> |
#ifndef UI_MAINWINDOW_H | #ifndef UI_MAINWINDOW_H | ||
#define UI_MAINWINDOW_H | #define UI_MAINWINDOW_H | ||
| Line 205: | Line 208: | ||
==Further Information == | ==Further Information == | ||
| − | * [[ | + | * [[Creating a signal to slot connection in Qt Designer]] |
| − | * [[How to create your first Qt application | + | * [[Archived:How to create your first Qt application]][[Category:MeeGo Harmattan]] [[Category:Symbian]] |
| + | [[Category:Code Examples]] | ||
Latest revision as of 04:17, 11 October 2012
Article Metadata
Code Example
Source file: Media:Alarmlist.zip
Tested with
SDK: Qt SDK
Article
Created: rahulvala
(06 Apr 2010)
Last edited: hamishwillee
(11 Oct 2012)
This code example shows shows how to layout a number of QWidgets in a MainWindow application, including QLabel, QCheckBox, and QTimeEdit. The QCheckBox and QTimeEdit are connected using signal and slot mechanism. The code is the UI layer for an "alarm" application - however the actual alarm code is not included.
Warning: The article title is deceptive - this doesn't actually show how to set alarms. It demonstrates how to layout a basic UI using QWidgets
Contents |
Header file
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
void changeEvent(QEvent *e);
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
Source file
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
ui_mainwindow.cpp
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QCheckBox>
#include <QtGui/QGroupBox>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QMainWindow>
#include <QtGui/QMenuBar>
#include <QtGui/QStatusBar>
#include <QtGui/QTimeEdit>
#include <QtGui/QToolBar>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QWidget *centralWidget;
QGroupBox *groupBox;
QLabel *label;
QLabel *label_2;
QLabel *label_3;
QCheckBox *checkBox;
QCheckBox *checkBox_2;
QCheckBox *checkBox_3;
QTimeEdit *timeEdit;
QTimeEdit *timeEdit_2;
QTimeEdit *timeEdit_3;
QMenuBar *menuBar;
QToolBar *mainToolBar;
QStatusBar *statusBar;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(600, 400);
centralWidget = new QWidget(MainWindow);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
groupBox = new QGroupBox(centralWidget);
groupBox->setObjectName(QString::fromUtf8("groupBox"));
groupBox->setGeometry(QRect(10, 20, 261, 251));
label = new QLabel(groupBox);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(20, 40, 46, 13));
label_2 = new QLabel(groupBox);
label_2->setObjectName(QString::fromUtf8("label_2"));
label_2->setGeometry(QRect(20, 100, 46, 13));
label_3 = new QLabel(groupBox);
label_3->setObjectName(QString::fromUtf8("label_3"));
label_3->setGeometry(QRect(20, 170, 46, 13));
checkBox = new QCheckBox(groupBox);
checkBox->setObjectName(QString::fromUtf8("checkBox"));
checkBox->setGeometry(QRect(80, 40, 70, 17));
checkBox_2 = new QCheckBox(groupBox);
checkBox_2->setObjectName(QString::fromUtf8("checkBox_2"));
checkBox_2->setGeometry(QRect(80, 100, 70, 17));
checkBox_3 = new QCheckBox(groupBox);
checkBox_3->setObjectName(QString::fromUtf8("checkBox_3"));
checkBox_3->setGeometry(QRect(80, 170, 70, 17));
timeEdit = new QTimeEdit(groupBox);
timeEdit->setObjectName(QString::fromUtf8("timeEdit"));
timeEdit->setGeometry(QRect(130, 40, 118, 22));
timeEdit_2 = new QTimeEdit(groupBox);
timeEdit_2->setObjectName(QString::fromUtf8("timeEdit_2"));
timeEdit_2->setGeometry(QRect(130, 100, 118, 22));
timeEdit_3 = new QTimeEdit(groupBox);
timeEdit_3->setObjectName(QString::fromUtf8("timeEdit_3"));
timeEdit_3->setGeometry(QRect(130, 160, 118, 22));
MainWindow->setCentralWidget(centralWidget);
menuBar = new QMenuBar(MainWindow);
menuBar->setObjectName(QString::fromUtf8("menuBar"));
menuBar->setGeometry(QRect(0, 0, 600, 20));
MainWindow->setMenuBar(menuBar);
mainToolBar = new QToolBar(MainWindow);
mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
statusBar = new QStatusBar(MainWindow);
statusBar->setObjectName(QString::fromUtf8("statusBar"));
MainWindow->setStatusBar(statusBar);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
groupBox->setTitle(QApplication::translate("MainWindow", "Alarm List", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("MainWindow", "Alarm 1", 0, QApplication::UnicodeUTF8));
label_2->setText(QApplication::translate("MainWindow", "Alarm 2", 0, QApplication::UnicodeUTF8));
label_3->setText(QApplication::translate("MainWindow", "Alarm 2", 0, QApplication::UnicodeUTF8));
checkBox->setText(QString());
checkBox_2->setText(QString());
checkBox_3->setText(QString());
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MAINWINDOW_H
Code example
The full source code presented in this article is available here File:Alarmlist.zip


