C++ (Qt)#ifndef PLOT_BOX_H#define PLOT_BOX_H #include <QObject> class plot_box : public QGroupBox{ Q_OBJECT; public: QString box_name; // Group box text QString current_val; // Current value QString thrsh_val; // Threshold value QString worst_val; // Worst value QString legend_1; // Legend 1 text QString legend_2; // Legend 2 text double x_data_1, x_data_2,; // Pointer to x values double y_data_1, y_data_2,; // Pointer to y values int size; // Size of x_data QString marker_text; // Marker text double marker_val; // Marker value }; #endif // PLOT_BOX_H
C++ (Qt) plot_box potc_box; potc_box.box_name = "test"; verticalLayout_Main->addWidget(potc_box);
//PlotBox.h#ifndef PLOT_BOX_H#define PLOT_BOX_H#include <QObject>#include <QGroupBox>#include <QLabel>#include <QLineEdit>class PlotBox: public QGroupBox{ Q_OBJECTpublic: PlotBox(const QString& title = "", QWidget* pwgt = 0); ~PlotBox(){}private: QLabel *m_lblFirst, *m_lblSecond; QLineEdit *m_leFirst, *m_leSecond;};#endif //PLOT_BOX_H//PlotBox.cpp#include "PlotBox.h"#include <QGridLayout>PlotBox::PlotBox(const QString& title, QWidget* pwgt): QGroupBox(title, pwgt){ QGridLayout *pgLayout = new QGridLayout; pgLayout->addWidget(m_lblFirst = new QLabel(tr("Первое поле:")), 0, 0, Qt::AlignRight); pgLayout->addWidget(m_lblSecond = new QLabel(tr("Второе поле:")), 1, 0, Qt::AlignRight); pgLayout->addWidget(m_leFirst = new QLineEdit, 0, 1); pgLayout->addWidget(m_leSecond = new QLineEdit, 1, 1); setLayout(pgLayout);}//main.cpp#include <QtGui/QtGui>#include "PlotBox.h"int main(int argc, char *argv[]){ //QCoreApplication a(argc, argv); QTextCodec::setCodecForTr(QTextCodec::codecForName("Windows-1251")); QApplication a(argc, argv); PlotBox w(QObject::tr("Группа элементов")); w.show(); return a.exec();}
C++ (Qt)PlotBox w(QObject::tr("text"));
C++ (Qt)plot_box *w = new plot_box;verticalLayout_Main->addWidget(w);
C++ (Qt)w->box_name="box name";
//PlotBox.hclass PlotBox: public QGroupBox{ Q_OBJECTpublic: PlotBox(const QString& title = "", const QString& lblFirst = "", const QString& lblSecond = "", QWidget* pwgt = 0); ~PlotBox(){} void setLabel(const QString& lblFirst, const QString& lblSecond){ m_lblFirst->setText(lblFirst); m_lblSecond->setText(lblSecond); } QString getFirstLabel() const {return m_lblFirst->text();} QString getSecondLabel() const {return m_lblSecond->text();}private: QLabel *m_lblFirst, *m_lblSecond; QLineEdit *m_leFirst, *m_leSecond;};//PlotBox.cppPlotBox::PlotBox(const QString& title, const QString& lblFirst, const QString& lblSecond, QWidget* pwgt): QGroupBox(title, pwgt){ QGridLayout *pgLayout = new QGridLayout; pgLayout->addWidget(m_lblFirst = new QLabel(lblFirst), 0, 0, Qt::AlignRight); pgLayout->addWidget(m_lblSecond = new QLabel(lblSecond), 1, 0, Qt::AlignRight); pgLayout->addWidget(m_leFirst = new QLineEdit, 0, 1); pgLayout->addWidget(m_leSecond = new QLineEdit, 1, 1); setLayout(pgLayout);}//main.cppint main(int argc, char *argv[]){ QTextCodec::setCodecForTr(QTextCodec::codecForName("Windows-1251")); QApplication a(argc, argv); PlotBox w(QObject::tr("Группа элементов"), QObject::tr("Первое поле:"), QObject::tr("Второе поле:")); //устанавливает новый текст в метках //w.setLabel(QObject::tr("1 поле:"), QObject::tr("2 поле:")); w.show(); return a.exec();}
C++ (Qt)class PlotBox: public QGroupBox{ Q_OBJECTpublic: PlotBox(const QString& title = "", const QString& lblFirst_text = "", QWidget* pwgt = 0); ~PlotBox(){} void setLabelText(const QString& lblFirst_text) { label_first->setText(lblFirst_text); label_first->setMaximumSize(60, 20); label_first->setMinimumSize(60, 20); } //QString getFirstLabel() const {return m_lblFirst->text();} // QString getSecondLabel() const {return m_lblSecond->text();}private: QLabel *label_first; };
C++ (Qt)PlotBox::PlotBox(const QString& title, const QString& lblFirst_text, QWidget* pwgt): QGroupBox(title, pwgt){//****** Horizontal layout Main ******* QHBoxLayout *horizontalLayout_main; horizontalLayout_main = new QHBoxLayout(); horizontalLayout_main->setObjectName(QString::fromUtf8("horizontalLayout_main")); //****** Vertical layout info ************ QVBoxLayout *verticalLayout_info; verticalLayout_info = new QVBoxLayout(); verticalLayout_info->setObjectName(QString::fromUtf8("verticalLayout_info")); horizontalLayout_main->addLayout(verticalLayout_info); //****** Curent ************ QHBoxLayout *horizontalLayout_current; horizontalLayout_current = new QHBoxLayout(); horizontalLayout_current->setObjectName(QString::fromUtf8("horizontalLayout_current")); horizontalLayout_current->addWidget(label_first = new QLabel(lblFirst_text)); setLayout(horizontalLayout_main);}
PlotBox *w = new PlotBox; w->setLabelText(QObject::tr("1 sad:")); verticalLayout_Main->addWidget(w);
setLayout(horizontalLayout_main);
//****** Curent ************ QHBoxLayout *horizontalLayout_current = new QHBoxLayout(); horizontalLayout_current->setObjectName(QString::fromUtf8("horizontalLayout_current")); horizontalLayout_current->addWidget(label_first = new QLabel(lblFirst_text)); setLayout(horizontalLayout_current);
C++ (Qt) void setPlot(const double &plotMin, const double &plotMax, const double &plotStep) { QFont plotFont("Times", 8, QFont::Light); plot_data->setCanvasLineWidth(0); plot_data->setAxisScale(0, plotMin, plotMax, plotStep); plot_data->setAxisFont(0, plotFont); plot_data->setMinimumWidth(100); plot_data->enableAxis(2,false); }
C++ (Qt)void setCurve1(const double &x_val1, const double &cur_val1, const int cur_size1) { QColor curvColor; QColor backGrndCol; curvColor.setRgb(153, 51, 255, 250); backGrndCol.setRgb(153, 51, 255, 50); curve_line1->setRenderHint(QwtPlotItem::RenderAntialiased); curve_backg1->setPen(backGrndCol); curve_backg1->setBrush(backGrndCol); curve_line1->setPen(curvColor); curve_line1->setData(x_val1, cur_val1, cur_size1); curve_backg1->setData(x_val1, cur_val1, cur_size1); curve_line1->attach(plot_data); curve_backg1->attach(plot_data); }