【发布时间】:2013-09-05 06:59:01
【问题描述】:
我在 Qt 中有一个 mainWindow 和一个 Dialog 。我在 MainWindow 打开两个图像。在我对 MainWindow 上的图像(裁剪、调整大小、旋转)进行操作之后。我想将图像发送到另一个 window (QDialog) 。我如何将其作为parameter 发送?我的部分代码如下;
MainWindow::MainWindow()
{
openButton_1 = new QPushButton(tr("Open"));
cropButton_1 = new QPushButton(tr("Crop"));
rotateButton_1 = new QPushButton(tr("Rotate"));
resizeButton_1 = new QPushButton(tr("Resize"));
doneButton = new QPushButton(tr("Done"));
....
....
....
....
....
connect(openButton_1, SIGNAL(clicked()), this, SLOT(open1()));
connect(openButton_2, SIGNAL(clicked()), this, SLOT(open2()));
connect(doneButton, SIGNAL(clicked()), this, SLOT(done()));
//打开新窗口的done()函数
void MainWindow::done()
{
CompareImage dialog(this);
dialog.exec();
}
//新的对话窗口
CompareImage::CompareImage( QWidget *parent ) : QDialog( parent )
{
pushButton = new QPushButton(tr("TesT"));
graphicsScene = new QGraphicsScene;
graphicsView = new QGraphicsView(graphicsScene);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget( pushButton );
mainLayout->addWidget( graphicsView );
setLayout( mainLayout );
}
// 这里还有我的 open() 函数
void MainWindow::open( int signal )
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open File"), QDir::currentPath());
if (!fileName.isEmpty()) {
QImage image(fileName);
if (image.isNull()) {
QMessageBox::information(this, tr("Image Viewer"),
tr("Cannot load %1.").arg(fileName));
return;
}
QGraphicsPixmapItem* item = new QGraphicsPixmapItem(QPixmap::fromImage(image));
if( signal == 1 )
{
graphicsScene_1->addItem(item);
graphicsView_1->show();
}
else if(signal == 2)
{
graphicsScene_2->addItem(item);
graphicsView_2->show();
}
}
}
使用QGraphicsPixmapItem* item 看起来不错,但我做不到.. 你能帮帮我吗?谢谢你的想法..
> 编辑:这里也是我的 open1 和 open2 函数,可以清楚地了解情况..
void MainWindow::open1()
{
open( 1 );
}
void MainWindow::open2()
{
open( 2 );
}
【问题讨论】:
-
我不知道你是如何发送信号来打开函数的?调用 open 时信号的值是多少?
-
我正在使用两个公共插槽:open1() 和 open2() 因此我可以发送信号.. 我不使用按钮调用 Open 函数。我在另一个函数中调用 open() 函数,其值如 open(1) 或 open(2)
-
It looks good idea to use QGraphicsPixmapItem* item but i couldnt make it你做不到是什么意思? -
@thuga 我尝试使用项目对象作为 QDialog 窗口的参数,但我无法做到。
-
@goGud 为什么?发生了什么?你到底尝试了什么?
标签: c++ image qt qmainwindow qdialog