int main(int argc, char *argv[]){ QApplication a(argc, argv); QWidget wgt; QTextEdit* edit = new QTextEdit(); QTextEdit* text = new QTextEdit(); QPushButton* but = new QPushButton("Go"); QBoxLayout* lo = new QBoxLayout(QBoxLayout::TopToBottom); lo->addWidget(edit,1); lo->addWidget(text,1); lo->addWidget(but, 1); wgt.setLayout(lo); text->setReadOnly(true); wgt.resize(600,200); wgt.show(); lbl.show(); QObject::connect(&but,SIGNAL(clicked()), &text,SLOT(AddColor(edit->toPlainText()))); return a.exec();}
SLOT(AddColor(edit->toPlainText()))
#include <QtGui/QApplication>#include <QWidget>#include <QPushButton>#include <QTextBrowser>#include <QBoxLayout>#include <QTextEdit>#include <QString>#include <QLabel>QString AddColor(QString text);QString ColorChoose();int main(int argc, char *argv[]){ QApplication a(argc, argv); QWidget wgt; QTextEdit* edit = new QTextEdit(""); QTextEdit* text = new QTextEdit(); QPushButton* but = new QPushButton("Go"); QBoxLayout* lo = new QBoxLayout(QBoxLayout::TopToBottom); lo->addWidget(edit,1); lo->addWidget(text,1); lo->addWidget(but, 1); wgt.setLayout(lo); text->setReadOnly(true); wgt.resize(600,200); wgt.show(); //QObject::connect(but,SIGNAL(clicked()), text,SLOT()))); return a.exec();}QString AddColor(QString text){ QString Text2; QString temp; for (int i=0;i<text.length();i++) { temp=text[i]; Text2.append("[color="); Text2.append(ColorChoose()); Text2.append("]"); Text2.append(temp); Text2.append("[/color]"); } return Text2;}QString ColorChoose(){ QString color; int range=15; int min=1; int colorID=rand() % (range+1) + min; switch (colorID) { case 1: color="Blue"; break; case 2: color="Red"; break; case 3: color="Yellow"; break; case 4: color="Purple"; break; case 5: color="Green"; break; case 6: color="Olive"; break; case 7: color="Crimson"; break; case 8: color="Magenta"; break; case 9: color="OrangeRed"; break; case 10: color="DeepPink"; break; case 11: color="DarkOrange"; break; case 12: color="Tomato"; break; case 13: color="Lime"; break; case 14: color="Aqua"; break; default: color="Black"; break; } return color;}