GUIプログラミングは以前から挑戦していたのですが、数回挫折してしばらくやっていませんでした。
気まぐれでやってみようと今回やってみました。
以前使ったソフトは、GTK+ Glade、Kilyx, QT Designerを使っていました。
今回は、QT Creatorを使ってみます。
外観は、QT Designerに比べてすっきりした感じがします。
とりあえず、HelloWoldを表示してみました。
ソースファイルは下記に示します。
URL:https://drive.google.com/file/d/0B0oSFZs-dbRZS2EwYjVBaFo3YXc/edit?usp=sharing
閉じるをクリックすると閉じるプログラムにしました。
ソースコードは以下
widget.h:
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
QLabel *text;
QPushButton *button;
QVBoxLayout *layout;
};
#endif // WIDGET_H
widget.cpp:
#include "widget.h"
#include <QApplication>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
layout=new QVBoxLayout(this);
text=new QLabel(this);
text->setText(QApplication::translate("widget","HelloWold",0,QApplication::UnicodeUTF8));
button=new QPushButton(this);
button->setText(QApplication::translate("Close","閉じる",0,QApplication::UnicodeUTF8));
layout->addWidget(text,0);
layout->addWidget(button,1);
this->setLayout(layout);
connect(button,SIGNAL(clicked()),this,SLOT(close()));
}
Widget::~Widget()
{
}
気まぐれでやってみようと今回やってみました。
以前使ったソフトは、GTK+ Glade、Kilyx, QT Designerを使っていました。
今回は、QT Creatorを使ってみます。
外観は、QT Designerに比べてすっきりした感じがします。
とりあえず、HelloWoldを表示してみました。
ソースファイルは下記に示します。
URL:https://drive.google.com/file/d/0B0oSFZs-dbRZS2EwYjVBaFo3YXc/edit?usp=sharing
閉じるをクリックすると閉じるプログラムにしました。
ソースコードは以下
widget.h:
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
QLabel *text;
QPushButton *button;
QVBoxLayout *layout;
};
#endif // WIDGET_H
widget.cpp:
#include "widget.h"
#include <QApplication>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
layout=new QVBoxLayout(this);
text=new QLabel(this);
text->setText(QApplication::translate("widget","HelloWold",0,QApplication::UnicodeUTF8));
button=new QPushButton(this);
button->setText(QApplication::translate("Close","閉じる",0,QApplication::UnicodeUTF8));
layout->addWidget(text,0);
layout->addWidget(button,1);
this->setLayout(layout);
connect(button,SIGNAL(clicked()),this,SLOT(close()));
}
Widget::~Widget()
{
}
コメント
コメントを投稿