c++ qt 主窗口设置图像后的对话框"确定"按钮
c++ qt Dialog 'OK' button after Mainwindow set image
我想要'ok'的新表单
From Mainwindow label Set image
image path : ./org/org.jpg
addim.h
private slots:
void on_buttonBox_accepted(); <---- 'OK' button
addim.cpp
void AddIm::on_ADdimg_cliekd()
system("raspistill -w 480 -h 360 -q 20 -o aaa.jpg -t 2");
QPixmap pix("./org/org.jpg);
ui2->QWidjet_org->setPixmap(pix); <--- QWidjet_org this label
我设法执行了有效的最小代码:
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "dialog.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
//This will change the image in the main window
void buttonHere();
//This will change the image in the dialog box
void buttonDialog();
private:
Ui::MainWindow *ui;
Dialog dialog;
//We need to save the image in QImage so it doesn't disappear
QImage image;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QObject::connect(ui->pushButton_here, SIGNAL(clicked(bool)), SLOT(buttonHere()));
QObject::connect(ui->pushButton_dialog, SIGNAL(clicked(bool)), SLOT(buttonDialog()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::buttonHere()
{
//We load the image
image.load(ui->label->text());
//We set the label image
ui->label_2->setPixmap(QPixmap::fromImage(image));
}
void MainWindow::buttonDialog()
{
//We call the function that changes the dialog image
dialog.setImage(ui->label->text());
//We show the dialog
dialog.show();
}
对话框
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
namespace Ui {
class Dialog;
}
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
//This function changes the image
void setImage(QString path);
private:
Ui::Dialog *ui;
//We need to save the image in QImage so it doesn't disappear
QImage image;
};
#endif // DIALOG_H
dialog.cpp
#include "dialog.h"
#include "ui_dialog.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::setImage(QString path)
{
//We load the image
image.load(path);
//We set the label image
ui->label->setPixmap(QPixmap::fromImage(image));
}
你得到这个结果
https://i.stack.imgur.com/gdqd7.png
https://i.stack.imgur.com/kbrsa.png
您应该创建一个资源文件,在其中导入图片,然后使用以下示例代码:
QPixmap pixmap_btn_hw(":/new/myPrefix/btn_hardware.png");
QIcon ButtonIcon_hw(pixmap_btn_hw);
ui->hardware_btn->setIcon(ButtonIcon_hw);
ui->hardware_btn->setIconSize(pixmap_btn_hw.rect().size());
ui->hardware_btn->setFocusPolicy(Qt::NoFocus);
启动外部程序" sytem()"是一个坏主意。以下要好得多:
QProcess *prpr = new QProcess();
prpr->setProcessChannelMode(QProcess::MergedChannels);
prpr->start("raspistill -w 480 -h 360 -q 20 -o aaa.jpg -t 2");
if (!prpr->waitForFinished())
{
// there was an error
}
else
{
// command worked!
}
相关文章:
- 如何在Qbutton的帮助下更改Q对话框的宽度
- 当对话框被接受时,如何用参数调用槽
- WinAPI 在单击第一个对话框上的按钮控件并销毁第一个对话框后创建第二个对话框
- 如何多次询问来自QML对话框的输入?
- 选择文件对话框错误
- 自定义对话框(源自QDialog)不会关闭(Android)
- 如何在 MFC 对话框中使用 OnDraw
- 在C++中创建文件夹选取器对话框的最简单方法是什么?
- 从资源视图访问对话框时出现问题
- 如何检测窗口当前是否正在运行模式对话框?
- "最小化"按钮不会出现在 MFC 对话框中
- 如何获取QNetworkConfiguration UserChoice对话框?
- 表单显示对话框函数错误,并且不执行下面的语句
- 如何在 VC6 中的对话框中将图标设置为按钮
- C++/Win32 构造函数不使用从对话框获取的字符串初始化变量
- 在 Win32 应用中,如果未选择文件夹并且用户单击"确定",则文件夹选择对话框将关闭
- c++ qt 主窗口设置图像后的对话框"确定"按钮
- 禁用对话框“确定”按钮MFC
- 如何确定当用户单击""Cancel""时 FindText 对话框已关闭
- MFC“确定/取消”对话框按钮替代