|
本帖最后由 Lvren 于 2013-1-19 21:10 编辑
关于槽的写法~如何使得一张图片通过按键切换为另一张图片~用槽写完后用不用在进行一次界面布局?现在每次执行程序就崩溃~
主要是槽的部分的写法不懂~
#include <QtGui>
#include <QPixmap>
#include "picturechange.h"
PictureChange::PictureChange(QWidget *parent) : QDialog(parent)
{
//QString picName;
picName="/home/common/my_program/picture/picture.jpg";
QLabel *label=new QLabel;
button_change=new QPushButton("change");
button_quit=new QPushButton("quit");
connect(button_change,SIGNAL(clicked()),this,SLOT(change_clicked()));
connect(button_quit,SIGNAL(clicked()),this,SLOT(close()));
pixmap=new QPixmap;
pixmap->load(picName);
label->setPixmap(*pixmap);
QVBoxLayout *leftlayout=new QVBoxLayout;
leftlayout->addWidget(button_change);
leftlayout->addWidget(button_quit);
leftlayout->addStretch();
QHBoxLayout *toplayout=new QHBoxLayout;
toplayout->addLayout(leftlayout);
toplayout->addWidget(label);
//label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
//label->setScaledContents(true);
//label->resize(window->size());
setLayout(toplayout);
setWindowTitle("picture change");
//setFixedHeight(sizeHint(),height());
}
void PictureChange::change_clicked()
{
QString picpath1,picpath2;
//QPixmap *pixmap;
picpath1="/home/common/my_program/picture/picture.jpg";
picpath2="/home/common/my_program/picture/picture2.jpg";
//QMessageBox::warning(this,"warning","change button is clickded");
//pixmap=new QPixmap(picpath2);
pixmap->load(picpath2);
label->setPixmap(*pixmap);
}
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|