방금 Qt를 배우기 시작했고 사진 이름 (콤보 박스에서)을 선택한 다음 푸시 버튼을 클릭하면 선택한 사진이 widget (?)에 나타날 수있는 간단한 프로그램을 만들고 싶습니다 (가능한 경우 동일한 창에). . 다음과 같이 표시되어야합니다.
지금까지 제가 직면 한 가장 큰 문제는 이러한 모든 개체를 연결하는 것입니다. 제대로 작동하도록 만들 수 없습니다.
또한 위젯에 사진을 업로드하려고했지만 전체 크기로만 나타나고 내 프로그램은 사진이되고 다른 것은 없습니다.
편집하다:
나는 그것을 작동하도록 노력하고 있지만 그것을 달성 할 수 없습니다 .. 그것은 내 코드입니다.
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_comboBox_currentIndexChanged(int index)
{
connect(ui->comboBox, SIGNAL(currentIndexChanged(int index)), this, SLOT(on_pushButton_clicked(int index)));
}
void MainWindow::choiceChanged(int index)
{
switch (index) {
case 0:
firstPicture();
break;
case 1:
secondPicture();
break;
case 2:
thirdPicture();
break;
}
}
void MainWindow::on_pushButton_clicked(int index)
{
connect(ui->pushButton, SIGNAL(on_pushButton_clicked(int)), this, SLOT(choiceChanged(int)));
}
void MainWindow::firstPicture(){
QPixmap image("C:/Documents/Aaaa.png");
ui->label->setPixmap(image);
}
void MainWindow::secondPicture(){
QPixmap image("C:/Documents/Bbbb.png");
ui->label->setPixmap(image);
}
void MainWindow::thirdPicture(){
QPixmap image("C:/Documents/Cccc.png");
ui->label->setPixmap(image);
}
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked(int index);
void choiceChanged(int index);
void on_comboBox_currentIndexChanged(int index);
void firstPicture();
void secondPicture();
void thirdPicture();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
레이아웃은 괜찮지 만 QLabel을 사용하여 이미지를 표시하는 것이 좋습니다.
그래서 내가 할 일입니다.
currentIndexChanged(int index)
또는 문자열 변형 을 선택합니다 . 설명서 참조 )clicked()
). 슬롯에서 QLabel에 그림을 삽입하는 것보다.그림을 설정하려면 다음을 수행하십시오.
QPixmap image("/path/to/image/chosen/image.jpg"); //choose the path accordingly to the variable stored that mirrors the state of the combobox.
ui->imageLabel->setPixmap(image); //change imageLabel to the name of your label.
당신은 갈 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다