-
-
Save tacchang001/2b9c05f31acd8c9b0ed4921316917339 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* http://ja.uwenku.com/question/p-xdsgakng-kv.html | |
*/ | |
#include "mainwindow.h" | |
#include <QApplication> | |
int main(int argc, char *argv[]) | |
{ | |
QApplication a(argc, argv); | |
MainWindow w; | |
w.show(); | |
return a.exec(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* https://www.webdevqa.jp.net/ja/qt/コンテンツに合わせてウィンドウのサイズを変更する/1073740067/ | |
*/ | |
#include <QStandardItemModel> | |
#include <QVBoxLayout> | |
#include <QTableWidget> | |
#include <QHeaderView> | |
#include <QPushButton> | |
#include <QLabel> | |
#include <QDebug> | |
#include "mainwindow.h" | |
#include "SubWindowA.h" | |
#include "SubWindowB.h" | |
/* | |
* | |
*/ | |
MainWindow::MainWindow(QWidget *parent) : | |
QWidget(parent) | |
{ | |
auto mainLayout = new QVBoxLayout(this); | |
{ | |
setLayout(mainLayout); | |
auto button1 = new QPushButton("Dialog 1"); | |
{ | |
connect(button1, &QPushButton::clicked, this, &MainWindow::onButton1Clicked); | |
} | |
mainLayout->addWidget(button1); | |
auto button2 = new QPushButton("Dialog 2"); | |
{ | |
connect(button2, &QPushButton::clicked, this, &MainWindow::onButton2Clicked); | |
} | |
mainLayout->addWidget(button2); | |
} | |
} | |
MainWindow::~MainWindow() | |
{ | |
if (_windowA != nullptr) | |
{ | |
_windowA->hide(); | |
_windowA->deleteLater(); | |
} | |
if (_windowB != nullptr) | |
{ | |
_windowB->hide(); | |
_windowB->deleteLater(); | |
} | |
} | |
void MainWindow::onButton1Clicked() | |
{ | |
_windowA = new SubWindowA; | |
// _windowA->raise(); | |
_windowA->show(); | |
connect(_windowA, &SubWindowA::close, this, &MainWindow::closedWindowA); | |
// this->hide(); | |
} | |
void MainWindow::onButton2Clicked() | |
{ | |
_windowB = new SubWindowB; | |
_windowB->show(); | |
_windowA->raise(); | |
// _windowA->activateWindow(); | |
// /* | |
// * https://kojinjigyou.org/4119/ | |
// */ | |
// _windowB->lower(); | |
// /* | |
// * WindowAの下に隠れるんじゃないのか? | |
// */ | |
// _windowB->stackUnder(_windowA); | |
connect(_windowB, &SubWindowB::close, this, &MainWindow::closedWindowB); | |
// this->hide(); | |
} | |
void MainWindow::closedWindowA() | |
{ | |
_windowA->hide(); | |
// this->show(); | |
delete _windowA; | |
_windowA = nullptr; | |
} | |
void MainWindow::closedWindowB() | |
{ | |
_windowB->hide(); | |
// this->show(); | |
delete _windowB; | |
_windowB = nullptr; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma | |
#include <QWidget> | |
class SubWindowA; | |
class SubWindowB; | |
class MainWindow : public QWidget | |
{ | |
Q_OBJECT | |
public: | |
explicit MainWindow(QWidget *parent = 0); | |
~MainWindow() override; | |
private slots: | |
void onButton1Clicked(); | |
void onButton2Clicked(); | |
void closedWindowA(); | |
void closedWindowB(); | |
private: | |
SubWindowA *_windowA; | |
SubWindowB *_windowB; | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "SubWindowA.h" | |
#include "ui_window_a.h" | |
SubWindowA::SubWindowA(QWidget *parent) | |
: QWidget(parent), | |
form(new Ui::Form) | |
{ | |
form->setupUi(this); | |
} | |
void SubWindowA::closeEvent(QCloseEvent *event) | |
{ | |
emit close(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <QWidget> | |
namespace Ui | |
{ | |
class Form; | |
}; | |
class SubWindowA : public QWidget | |
{ | |
Q_OBJECT | |
public: | |
explicit SubWindowA(QWidget *parent = 0); | |
~SubWindowA() override = default; | |
signals: | |
void close(); | |
public slots: | |
void closeEvent(QCloseEvent *event) override; | |
private: | |
Ui::Form *form; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "SubWindowB.h" | |
#include "ui_window_b.h" | |
SubWindowB::SubWindowB(QWidget *parent) | |
: QDialog(parent), | |
form(new Ui::FormB) | |
{ | |
form->setupUi(this); | |
} | |
void SubWindowB::closeEvent(QCloseEvent *event) | |
{ | |
emit close(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <QDialog> | |
class QTableWidget; | |
namespace Ui | |
{ | |
class FormB; | |
}; | |
class SubWindowB : public QDialog | |
{ | |
Q_OBJECT | |
public: | |
explicit SubWindowB(QWidget *parent = 0); | |
~SubWindowB() override = default; | |
signals: | |
void close(); | |
public slots: | |
void closeEvent(QCloseEvent *event) override; | |
private: | |
Ui::FormB *form; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment