目录
实验效果,使用方法和功能
初始界面:
点击线条右边的修改
再修改填充,调整线宽
将形状改为RoundRect
附录:
文件一览:
代码
main.cpp
#include <QApplication>
#include <widget.h>
int main(int argc,char* argv[])
{
QApplication a(argc,argv);
Widget w;
w.show();
return a.exec();
}
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QComboBox>
#include <QFrame>
#include <QSpinBox>
#include <paintarea.h>
class Widget:public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget* parent = 0);
~Widget();
protected:
QComboBox* shapeComboBox;
QFrame* colorFrame;
QFrame* brushColorFrame;
QSpinBox* widthSpinBox;
PaintArea* paintArea;
public slots:
//修改形状槽函数
void slotShape(int);
//修改画笔槽函数
void slotPenColor();
//修改笔宽槽函数
void slotPenWidth(int);
//修改画刷槽函数
void slotBrushColor();
};
#endif // WIDGET_H
widget.cpp
#include <Widget.h>
#include <QLabel>
#include <QComboBox>
#include <QPushButton>
#include <QSpinBox>
#include <paintarea.h>
#include <QColor>
#include <QColorDialog>
Widget::Widget(QWidget *parent): QWidget(parent)
{
//设置主窗口大小
this->resize(700,400);
QLabel * SharpLabel = new QLabel("形状:",this);
shapeComboBox = new QComboBox(this);
SharpLabel->setGeometry(430,20,60,40);
shapeComboBox->setGeometry(500,20,150,40);
shapeComboBox->addItem("Line",PaintArea::Line);
shapeComboBox->addItem("Rectangle",PaintArea::Rectangle);
shapeComboBox->addItem("RoundRect",PaintArea::RoundRect)