.h的代码:
#ifndef FORM4_H
#define FORM4_H
#include <QWidget>
#include <QDialog>
#include <QInputDialog>
#include <QGridLayout>
#include <QComboBox>
#include <QLabel>
namespace Ui {
class Form4;
}
class Form4 : public QWidget
{
Q_OBJECT
public:
explicit Form4(QWidget *parent = 0);
~Form4();
QVBoxLayout *layout;
QPushButton *colorPushButton;
QFrame *colorFrame;
QLabel *label;
QComboBox *comboBox;
private:
Ui::Form4 *ui;
private slots:
void slotOpenColorDlg();
};
#endif // FORM4_H
cpp的代码:
#include "form4.h"
#include "ui_form4.h"
#include <QInputDialog>
#include <QColorDialog>
#include <QPushButton>
#include <QColor>
Form4::Form4(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form4)
{
ui->setupUi(this);
colorPushButton=new QPushButton();
colorPushButton->setText(tr("场景颜色"));
colorFrame=new QFrame();
colorFrame->setFrameShape(QFrame::Box);
colorFrame->setAutoFillBackground(true);
comboBox = new QComboBox();
QStringList strings;
strings << tr("原子类型") << tr("0") << tr("1") << tr("2") ;
comboBox->addItems(strings);
layout = new QVBoxLayout(this);
layout->addWidget(comboBox);
layout->addWidget(colorPushButton);
layout->addWidget(colorFrame);
layout->setMargin(15);
layout->setSpacing(10);
this->setLayout(layout);
connect(colorPushButton,SIGNAL(cliked()),this,SLOT(slotOpenColorDlg()));
connect(comboBox,SIGNAL(currentIndexChanged(int)),
this,SLOT(selectChanged(int)));
}
Form4::~Form4()
{
delete ui;
}
void Form4::slotOpenColorDlg()
{
QColor color=QColorDialog::getColor(Qt::blue);
if(color.isValid())
{
colorFrame->setPalette(QPalette(color));
}
}
6 个解决方案
#1
slotOpenColorDlg能走到吗 看看你的connect的返回值是否有效
#2
不懂,求指导。。
#3
就是说你的信号槽是否建立了连接
#4
怎么验证是否建立了连接?我看书上是用了这种方法,我这样怎么就不行了呢?
#5
connect(colorPushButton,SIGNAL(clicked()),this,SLOT(slotOpenColorDlg()));
你的clicked()函数名写错了,少了个c
#6
晕!好了@居然是个这,郁闷。谢谢了。。
#1
slotOpenColorDlg能走到吗 看看你的connect的返回值是否有效
#2
不懂,求指导。。
#3
就是说你的信号槽是否建立了连接
#4
怎么验证是否建立了连接?我看书上是用了这种方法,我这样怎么就不行了呢?
#5
connect(colorPushButton,SIGNAL(clicked()),this,SLOT(slotOpenColorDlg()));
你的clicked()函数名写错了,少了个c
#6
晕!好了@居然是个这,郁闷。谢谢了。。