Namespaces
Variants
Actions
Revision as of 04:17, 11 October 2012 by hamishwillee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to create To Do List in Qt

Jump to: navigation, search
Article Metadata

Code Example
Source file: Media:Dolist.zip

Article
Created: rahulvala (06 Apr 2010)
Last edited: hamishwillee (11 Oct 2012)

Contents

Overview

This article shows how to create QWidget-based To do List. The example uses Qt's QGroupBox, QTimeEdit, QDateEdit, and QTextEdit.

Prerequisite

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/QDateEdit>
#include <QtGui/QGroupBox>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QMainWindow>
#include <QtGui/QMenuBar>
#include <QtGui/QStatusBar>
#include <QtGui/QTextEdit>
#include <QtGui/QTimeEdit>
#include <QtGui/QToolBar>
#include <QtGui/QWidget>
 
QT_BEGIN_NAMESPACE
 
class Ui_MainWindow
{
public:
QWidget *centralWidget;
QGroupBox *groupBox;
QDateEdit *dateEdit;
QTimeEdit *timeEdit;
QLabel *label;
QLabel *label_2;
QTextEdit *textEdit;
QLabel *label_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, 10, 321, 211));
dateEdit = new QDateEdit(groupBox);
dateEdit->setObjectName(QString::fromUtf8("dateEdit"));
dateEdit->setGeometry(QRect(160, 30, 111, 22));
timeEdit = new QTimeEdit(groupBox);
timeEdit->setObjectName(QString::fromUtf8("timeEdit"));
timeEdit->setGeometry(QRect(160, 60, 118, 22));
label = new QLabel(groupBox);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(30, 30, 61, 16));
label_2 = new QLabel(groupBox);
label_2->setObjectName(QString::fromUtf8("label_2"));
label_2->setGeometry(QRect(30, 70, 46, 13));
textEdit = new QTextEdit(groupBox);
textEdit->setObjectName(QString::fromUtf8("textEdit"));
textEdit->setGeometry(QRect(110, 120, 191, 71));
label_3 = new QLabel(groupBox);
label_3->setObjectName(QString::fromUtf8("label_3"));
label_3->setGeometry(QRect(30, 130, 51, 16));
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", "To do list", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("MainWindow", "Date", 0, QApplication::UnicodeUTF8));
label_2->setText(QApplication::translate("MainWindow", "Time", 0, QApplication::UnicodeUTF8));
label_3->setText(QApplication::translate("MainWindow", "Enter Text", 0, QApplication::UnicodeUTF8));
} // retranslateUi
 
};
 
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
 
QT_END_NAMESPACE
 
#endif // UI_MAINWINDOW_H

output window

This code snippet will reflect the output given below.

Todolist.jpg

Source code

The source code of this file is given at this link.File:Dolist.zip

--rahulvala 06:20, 6 April 2010 (UTC)

141 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