Hi,
i'm new in qt. and i have a minwindow and a second window. the 1st window has 3 frames and the 2nd has only one. my question: how to swap after clicked a button the 2nd window's frame with the 3rd frame of the 1st window? here are my codes:
.h
#ifndef FIRSTDIALOG_H
#define FIRSTDIALOG_H
#include <QDialog>
#include <QFrame>
#include <QWidget>
#include <QListWidgetItem>
namespace Ui {
class FirstDialog;
}
{
Q_OBJECT
public:
explicit FirstDialog
(QWidget *parent
= 0);
~FirstDialog();
private:
Ui::FirstDialog *ui;
};
#endif // FIRSTDIALOG_H
//---------------------------------------------
.cpp
#include "firstdialog.h"
#include "ui_firstdialog.h"
#include <QWidget>
FirstDialog
::FirstDialog(QWidget *parent
) : ui(new Ui::FirstDialog)
{
ui->setupUi(this);
}
FirstDialog::~FirstDialog()
{
delete ui;
}
.h
#ifndef FIRSTDIALOG_H
#define FIRSTDIALOG_H
#include <QDialog>
#include <QFrame>
#include <QWidget>
#include <QListWidgetItem>
namespace Ui {
class FirstDialog;
}
class FirstDialog : public QDialog
{
Q_OBJECT
public:
explicit FirstDialog(QWidget *parent = 0);
~FirstDialog();
private:
Ui::FirstDialog *ui;
QFrame *frame_4;
};
#endif // FIRSTDIALOG_H
//---------------------------------------------
.cpp
#include "firstdialog.h"
#include "ui_firstdialog.h"
#include <QWidget>
FirstDialog::FirstDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::FirstDialog)
{
ui->setupUi(this);
}
FirstDialog::~FirstDialog()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QLabel>
//#include <QListWidget>
//#include <QWidget>
#include <QListWidgetItem>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private slots:
void on_pushButton_1_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
//-------------------------------------------
.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "firstdialog.h"
#include <QLabel>
#include <QPixmap>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
QPixmap pix
("C:/Users/Infonet/Documents/frames_test/logo6_DT.png");
int w = ui->label_1->width();
int h = ui->label_1->height();
ui->label_1->setPixmap(pix.scaled(w,h,Qt::KeepAspectRatio));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_1_clicked()
{
FirstDialog *firstdia = new FirstDialog;
firstdia->show();
}
.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QLabel>
//#include <QListWidget>
//#include <QWidget>
#include <QListWidgetItem>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_1_clicked();
private:
Ui::MainWindow *ui;
QFrame *frame_1;
QFrame *frame_2;
QFrame *frame_3;
};
#endif // MAINWINDOW_H
//-------------------------------------------
.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "firstdialog.h"
#include <QLabel>
#include <QPixmap>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QPixmap pix("C:/Users/Infonet/Documents/frames_test/logo6_DT.png");
int w = ui->label_1->width();
int h = ui->label_1->height();
ui->label_1->setPixmap(pix.scaled(w,h,Qt::KeepAspectRatio));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_1_clicked()
{
FirstDialog *firstdia = new FirstDialog;
firstdia->show();
}
To copy to clipboard, switch view to plain text mode
thanks.
Bookmarks