关于QPushButton,设置点击后无反应
意在停靠窗口中加入彩选择颜色按钮,可是加入之后点击没有colorBox弹出?代码如下,求大神解答!
.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));
}
}
[解决办法]
slotOpenColorDlg能走到吗 看看你的connect的返回值是否有效
[解决办法]