1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Qt rensyu

Posted at

#include "mainwindow.h"
#include "ui_mainwindow.h"

#include
#include
#include
#include

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(testFunc1()));

connect(ui->radioButton, SIGNAL(clicked()), this, SLOT(testFunc2()));
connect(ui->radioButton_2, SIGNAL(clicked()), this, SLOT(testFunc2()));

connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(testFunc3()));

connect(ui->pushButton_3, SIGNAL(clicked()), this, SLOT(testFunc4()));

}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::testFunc1()
{
QString text = ui->textEdit->toPlainText();

qDebug("aaa");
ui->label->setText(text);

}

void MainWindow::testFunc2()
{
qDebug("aaa");
bool female = ui->radioButton_2->isChecked();
ui->label_2->setText(female ? "女性が選択されました" : "男性が選択されました");
ui->label_2->setStyleSheet(female ? "color: red" : "color: blue");
}

void MainWindow::testFunc3()
{
str.setNum(num);
ui->label_3->setText(str);
qDebug("aaa");
num++;
}

void MainWindow::testFunc4()
{
QGraphicsScene* scene = new QGraphicsScene(this); // newして保持する
QImage image("C:/tmp/hoge.png");

QGraphicsPixmapItem* image_item = new QGraphicsPixmapItem(QPixmap::fromImage(image));
scene->addItem(image_item);

ui->graphicsView_2->setScene(scene);
ui->graphicsView_2->fitInView(image_item, Qt::KeepAspectRatio);

}

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();

public slots:
void testFunc1();
void testFunc2();
void testFunc3();
void testFunc4();

private:
Ui::MainWindow *ui;
QString str = "0";
int num = 0;
};
#endif // MAINWINDOW_H

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?