新建一个基于对话框的工程,取消界面选项。
头文件如下:
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QFrame>
#include <QGridLayout>
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
~Dialog();
private:
QPushButton *colorbtn;
QFrame *colorFrame;
QGridLayout *mainlayout;
public slots:
void showcolors();
};
#endif // DIALOG_H
.cpp文件如下:
#include "dialog.h"
#include <QColor>
#include <QColorDialog>
#include <QPushButton>
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
{
colorbtn=new QPushButton;
colorbtn->setText("颜色选择按钮");
colorFrame =new QFrame;
colorFrame->setFrameShape(QFrame::Box);
colorFrame->setAutoFillBackground(true);
mainlayout=new QGridLayout(this);
mainlayout->addWid