int main(int argc, char *argv[]) { QApplication app(argc, argv); QTextEdit *editor = new QTextEdit; QTextDocument *document = new QTextDocument(editor); QTextCursor cursor(document); QImage image(64, 64, QImage::Format_RGB32); image.fill(qRgb(255, 160, 128)); //! [Adding a resource] document->addResource(QTextDocument::ImageResource, QUrl("mydata://image.png"), QVariant(image)); //! [Adding a resource] //! [Inserting an image with a cursor] QTextImageFormat imageFormat; imageFormat.setName("mydata://image.png"); cursor.insertImage(imageFormat); //! [Inserting an image with a cursor] cursor.insertBlock(); cursor.insertText("Code less. Create more."); editor->setDocument(document); editor->setWindowTitle(tr("Text Document Images")); editor->resize(320, 480); editor->show(); //! [Inserting an image using HTML] editor->append("<img src=\"mydata://image.png\" />"); //! [Inserting an image using HTML] return app.exec(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QTextEdit editor; FilterObject filter; filter.setFilteredObject(&editor); editor.show(); return app.exec(); }
void MainWindow::slotSourceDownloaded() { QNetworkReply* reply = qobject_cast<QNetworkReply*>(const_cast<QObject*>(sender())); QTextEdit* textEdit = new QTextEdit(NULL); textEdit->setAttribute(Qt::WA_DeleteOnClose); textEdit->show(); textEdit->setPlainText(reply->readAll()); reply->deleteLater(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QTextEdit textEdit; textEdit.show(); return app.exec(); }
void MainWindow::viewSource() { QTextEdit* textEdit = new QTextEdit(NULL); textEdit->setAttribute(Qt::WA_DeleteOnClose); textEdit->adjustSize(); textEdit->move(this->geometry().center() - textEdit->rect().center()); textEdit->show(); view->page()->toHtml(invoke(textEdit, &QTextEdit::setPlainText)); }
int main(int argv, char **args) { // Erzeugt das Hauptprogramm QApplication app(argv, args); // Erzeugt ein "Widgets" (z.B. Scrollbalken, Buttons - hier ein Textfeld/Fenster zum schreiben) QTextEdit textEdit; // Zeigt das Widgets an. textEdit.show(); // Hier startet QT seine Hauptschleife, um Events abzufangen (Mausklick, Tastaturanschlag) return app.exec(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QTextEdit *editor = new QTextEdit; QTextDocument *document = new QTextDocument(editor); QTextCursor cursor(document); QTextImageFormat imageFormat; imageFormat.setName(":/images/advert.png"); cursor.insertImage(imageFormat); QTextBlock block = cursor.block(); QTextFragment fragment; QTextBlock::iterator it; for (it = block.begin(); !(it.atEnd()); ++it) { fragment = it.fragment(); if (fragment.contains(cursor.position())) break; } //! [0] if (fragment.isValid()) { QTextImageFormat newImageFormat = fragment.charFormat().toImageFormat(); if (newImageFormat.isValid()) { newImageFormat.setName(":/images/newimage.png"); QTextCursor helper = cursor; helper.setPosition(fragment.position()); helper.setPosition(fragment.position() + fragment.length(), QTextCursor::KeepAnchor); helper.setCharFormat(newImageFormat); //! [0] //! [1] } //! [1] //! [2] } //! [2] cursor.insertBlock(); cursor.insertText("Code less. Create more."); editor->setDocument(document); editor->setWindowTitle(tr("Text Document Image Format")); editor->resize(320, 480); editor->show(); return app.exec(); }
int main(int argc, char ** argv) { QApplication app{argc, argv}; double const table[] { 78.0, 78.0, 78.0, 0.0, 0.0, 78.0, 69.0, 56.0, 0.0}; QTextEdit edit; setHtml(&edit, toTable(std::begin(table), std::end(table), 3, [](double arg){ return QString::number(arg, 'f', 1); }, "width=\"100%\"")); edit.setReadOnly(true); edit.show(); return app.exec(); }
void QtAboutWidget::handleLicenseClicked() { QTextEdit* text = new QTextEdit(); text->setAttribute(Qt::WA_DeleteOnClose); text->setReadOnly(true); QFile file(":/COPYING"); file.open(QIODevice::ReadOnly); QTextStream in(&file); in.setCodec("UTF-8"); text->setPlainText(in.readAll()); file.close(); text->resize(500, 600); text->show(); text->activateWindow(); }
int main( int argc, char **argv ) { QApplication app( argc, argv ); QTextEdit log; EventWidget widget; QObject::connect( &widget, SIGNAL(gotEvent(const QString &)), &log, SLOT(append(const QString &)) ); log.show(); widget.show(); return app.exec(); }
int main(int argc, char *argv[]) { QWidget *parent = 0; QString aStringContainingHTMLtext("<h1>Scribe Overview</h1>"); QApplication app(argc, argv); //! [1] QTextEdit *editor = new QTextEdit(parent); editor->setHtml(aStringContainingHTMLtext); editor->show(); //! [1] return app.exec(); }
QTextEdit* Widgets::createMdiChild() { static int sequenceNumber = 1; QString curFile = tr("document%1.txt").arg(sequenceNumber++); QTextEdit* child = new QTextEdit; child->setWindowIcon(QIcon(":/res/new.png")); child->setWindowTitle(curFile + "[*]"); QMdiSubWindow* subWindow = m_mdiArea->addSubWindow(child); subWindow->setWindowState(Qt::WindowMaximized); // subWindow->resize( m_mdiArea->width(), m_mdiArea->height()); child->show(); return child; }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QTextEdit *editor = new QTextEdit(); QTextCursor cursor(editor->textCursor()); cursor.movePosition(QTextCursor::Start); QTextCharFormat plainFormat(cursor.charFormat()); QTextCharFormat headingFormat = plainFormat; headingFormat.setFontWeight(QFont::Bold); headingFormat.setFontPointSize(16); QTextCharFormat emphasisFormat = plainFormat; emphasisFormat.setFontItalic(true); QTextCharFormat qtFormat = plainFormat; qtFormat.setForeground(QColor("#990000")); QTextCharFormat underlineFormat = plainFormat; underlineFormat.setFontUnderline(true); //! [0] cursor.insertText(tr("Character formats"), headingFormat); cursor.insertBlock(); cursor.insertText(tr("Text can be displayed in a variety of " "different character formats. "), plainFormat); cursor.insertText(tr("We can emphasize text by ")); cursor.insertText(tr("making it italic"), emphasisFormat); //! [0] cursor.insertText(tr(", give it a "), plainFormat); cursor.insertText(tr("different color "), qtFormat); cursor.insertText(tr("to the default text color, "), plainFormat); cursor.insertText(tr("underline it"), underlineFormat); cursor.insertText(tr(", and use many other effects."), plainFormat); editor->setWindowTitle(tr("Text Document Character Formats")); editor->resize(320, 480); editor->show(); return app.exec(); }
void MainWindow::on_actionAbout_triggered() { QTextEdit *pTxt = new QTextEdit(this); pTxt->setWindowFlags(Qt::Window); //or Qt::Tool, Qt::Dialog if you like pTxt->setReadOnly(true); pTxt->append("qIffTool by Ilkka Prusi 2011"); pTxt->append(""); pTxt->append("This program is free to use and distribute. No warranties of any kind."); pTxt->append("Program uses Qt 4.7.2 under LGPL v. 2.1"); pTxt->append(""); pTxt->append("Keyboard shortcuts:"); pTxt->append(""); pTxt->append("F = open file"); pTxt->append("Esc = close"); pTxt->append("? = about (this dialog)"); pTxt->append(""); pTxt->show(); }
void MainDock::help() { //pd Qt version dependent #if QT_VERSION >= 0x040200 QDesktopServices::openUrl(QUrl("Readme.txt")); #else QFile readmeFile("Readme.txt"); readmeFile.open(QIODevice::ReadOnly); QTextStream readmeStream(&readmeFile); QString readmeString = readmeStream.readAll(); //won't close automaticaly QTextEdit* readmeTXE = new QTextEdit(0); readmeTXE->setMinimumSize(500, 300); readmeTXE->setWindowTitle("Parallel Worlds Help"); readmeTXE->show(); readmeTXE->setReadOnly(true); readmeTXE->setPlainText(readmeString); #endif }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QTextEdit *editor = new QTextEdit(); QTextCursor cursor(editor->textCursor()); cursor.movePosition(QTextCursor::Start); QTextCharFormat plainFormat(cursor.charFormat()); QTextCharFormat colorFormat = plainFormat; colorFormat.setForeground(Qt::red); cursor.insertText(tr("Text can be displayed in a variety of " "different character " "formats. "), plainFormat); cursor.insertText(tr("We can emphasize text by making it ")); cursor.insertText(tr("italic, give it a different color ")); cursor.insertText(tr("to the default text color, underline it, ")); cursor.insertText(tr("and use many other effects.")); QString searchString = tr("text"); QTextDocument *document = editor->document(); //! [0] QTextCursor newCursor(document); while (!newCursor.isNull() && !newCursor.atEnd()) { newCursor = document->find(searchString, newCursor); if (!newCursor.isNull()) { newCursor.movePosition(QTextCursor::WordRight, QTextCursor::KeepAnchor); newCursor.mergeCharFormat(colorFormat); } //! [0] //! [1] } //! [1] editor->setWindowTitle(tr("Text Document Find")); editor->resize(320, 480); editor->show(); return app.exec(); }
int main( int argc, char** argv ) { QApplication app( argc, argv ); MainWindow mainWindow;; mainWindow.show(); #if 0 QTextEdit textEdit; textEdit.setReadOnly( true ); textEdit.show(); #endif Match match; match.add( new TestBot( "test1" ) ); match.add( new TestBot( "test2" ) ); match.add( new Arena() ); match.display(); return app.exec(); }
int main(int argc, char * argv[]) { int rows = 6; int columns = 2; QApplication app(argc, argv); QTextEdit *textEdit = new QTextEdit; QTextCursor cursor(textEdit->textCursor()); cursor.movePosition(QTextCursor::Start); QTextTableFormat tableFormat; tableFormat.setAlignment(Qt::AlignHCenter); tableFormat.setCellPadding(2); tableFormat.setCellSpacing(2); QTextTable *table = cursor.insertTable(rows, columns); table->setFormat(tableFormat); QTextCharFormat boldFormat; boldFormat.setFontWeight(QFont::Bold); QTextBlockFormat centerFormat; centerFormat.setAlignment(Qt::AlignHCenter); cursor.mergeBlockFormat(centerFormat); cursor = table->cellAt(0, 0).firstCursorPosition(); cursor.insertText(("Details"), boldFormat); cursor = table->cellAt(1, 0).firstCursorPosition(); cursor.insertText("Alan"); cursor = table->cellAt(1, 1).firstCursorPosition(); cursor.insertText("5, Pickety Street"); //! [0] table->mergeCells(0, 0, 1, 2); //! [0] //! [1] table->splitCell(0, 0, 1, 1); //! [1] textEdit->show(); return app.exec(); }
int main (int argc, char * argv[]) { QStringList lineList; QString curLine; Dictionary myDict(argv[2]); QApplication myApp(argc, argv); QTextEdit wid; wid.setMinimumSize(500,300); wid.setAcceptRichText(true); QString word; QTextStream stream(&word); QFile myFile(argv[1]); myFile.open(QIODevice::ReadOnly); QTextStream inFile(&myFile); while(!inFile.atEnd()) { curLine = inFile.readLine(); //file is read lineList = curLine.split(QRegExp("\\b"), QString::SkipEmptyParts); //the string is split into parts for (int c = 0; c < lineList.size(); c++) { if (myDict.dictLook(lineList[c]) == 0) //if the word was misspelled, then { stream << "<font color=red>"; //red font tags are placed around the word stream << lineList[c]; stream << "</font>"; } else { stream << lineList[c]; //otherwise they are just outputted } } wid.append(word); //printed to text editor word = ""; //string cleared } wid.show(); return myApp.exec(); }
void CQTOpenGLMainWindow::POVRaySceneXMLPopUp() { /* Set the text window up */ QTextEdit* pcPOVRayOutput = new QTextEdit(); /* Calculate the geometry of the window so that it's 1/4 of the main window and placed in the exact center of it */ QRect cGeom = geometry(); cGeom.setBottomRight(geometry().center()); cGeom.moveCenter(geometry().center()); pcPOVRayOutput->setGeometry(cGeom); /* This window steals all input */ pcPOVRayOutput->setWindowModality(Qt::ApplicationModal); /* You can't modify its contents (but can copy-paste them) */ pcPOVRayOutput->setReadOnly(true); /* Set nice document name and window title */ pcPOVRayOutput->setDocumentTitle("ARGoS-POVRay XML camera config"); pcPOVRayOutput->setWindowTitle("ARGoS-POVRay XML camera config"); /* Set the actual text to visualize */ pcPOVRayOutput->setPlainText(GetPOVRaySceneXMLData()); /* Finally, show the resulting window */ pcPOVRayOutput->show(); }
void ComputationalResultsTableView::showLogFile() { MongoDatabase *db = MongoDatabase::instance(); mongo::GridFS fs(*db->connection(), "chem", "fs"); mongo::BSONObj *obj = static_cast<mongo::BSONObj *>(currentIndex().internalPointer()); if (obj) { const char *file_name = obj->getStringField("log_file"); mongo::GridFile file = fs.findFile(file_name); if (!file.exists()) { QMessageBox::critical(this, "Error", "Failed to load output file."); return; } // load file into a buffer std::stringstream stream; file.write(stream); QTextEdit *viewer = new QTextEdit(this); viewer->resize(500, 600); viewer->setWindowFlags(Qt::Dialog); viewer->setWindowTitle(file_name); viewer->setReadOnly(true); std::string file_data_string = stream.str(); viewer->setText(file_data_string.c_str()); viewer->show(); } else { QMessageBox::critical(this, "Error", "Failed to load output file."); } }
int main(int argc, char *argv[]) { QApplication myApp(argc, argv); if (argc != 3) { qDebug() << "Error: invalid usage. \nUsage: <file> <language>"; return 1; } // initialize a widget for outputting the results QTextEdit myWidget; myWidget.setMinimumSize(500,300); myWidget.setAcceptRichText(true); // File input variables QStringList inWords; QString text; // Map for missed words QMap<QString, int> missedList; // Input words from file, get rid of punctuation QFile inFile(myApp.arguments()[1]); if (inFile.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in(&inFile); text = in.readAll(); inWords = text.split(QRegExp("\\W+"), QString::SkipEmptyParts); } else { qDebug() << "Error: File could not be found OR doesn't exist!"; return 1; } // if language is american use the american-english dictionary if (myApp.arguments()[2] == "american") { QString file = QString("/usr/share/dict/american-english"); // initialize the dictionary Dictionary myAmericanDict(file); // create the misspelled word map myAmericanDict.isMisspelled(inWords); // output the map missedList = myAmericanDict.getMissedWords(); } else if (myApp.arguments()[2] == "british") { QString file = QString("/usr/share/dict/british-english"); // initialize the dictionary Dictionary myBritishDict(file); // create the misspelled word map myBritishDict.isMisspelled(inWords); // output the map missedList = myBritishDict.getMissedWords(); } // if language specified is not an option, output error and exit else { qDebug() << "Error: User specified dictionary not found!"; return 1; } // variables for formatting misspelled words QString sred = "<font color = '#ff0000'>"; QString ered = "</font>"; QString temp; // go through the missedspelled words and color the word // in text red foreach(const QString &str, missedList.keys()) { if (text.contains(str)) { temp = sred+str+ered; text.replace(str, temp); } } // append and show the formatted text myWidget.append(text); myWidget.show(); return myApp.exec(); //return 0; }
int main(int argc, char *argv[]) { QApplication app(argc, argv); //! [0] QTextEdit *editor = new QTextEdit(); QTextCursor cursor(editor->textCursor()); //! [0] cursor.movePosition(QTextCursor::Start); QTextBlockFormat blockFormat = cursor.blockFormat(); blockFormat.setTopMargin(4); blockFormat.setLeftMargin(4); blockFormat.setRightMargin(4); blockFormat.setBottomMargin(4); cursor.setBlockFormat(blockFormat); cursor.insertText(tr("This contains plain text inside a " "text block with margins to keep it separate " "from other parts of the document.")); cursor.insertBlock(); //! [1] QTextBlockFormat backgroundFormat = blockFormat; backgroundFormat.setBackground(QColor("lightGray")); cursor.setBlockFormat(backgroundFormat); //! [1] cursor.insertText(tr("The background color of a text block can be " "changed to highlight text.")); cursor.insertBlock(); QTextBlockFormat rightAlignedFormat = blockFormat; rightAlignedFormat.setAlignment(Qt::AlignRight); cursor.setBlockFormat(rightAlignedFormat); cursor.insertText(tr("The alignment of the text within a block is " "controlled by the alignment properties of " "the block itself. This text block is " "right-aligned.")); cursor.insertBlock(); QTextBlockFormat paragraphFormat = blockFormat; paragraphFormat.setAlignment(Qt::AlignJustify); paragraphFormat.setTextIndent(32); cursor.setBlockFormat(paragraphFormat); cursor.insertText(tr("Text can be formatted so that the first " "line in a paragraph has its own margin. " "This makes the text more readable.")); cursor.insertBlock(); QTextBlockFormat reverseFormat = blockFormat; reverseFormat.setAlignment(Qt::AlignJustify); reverseFormat.setTextIndent(32); cursor.setBlockFormat(reverseFormat); cursor.insertText(tr("The direction of the text can be reversed. " "This is useful for right-to-left " "languages.")); editor->setWindowTitle(tr("Text Block Formats")); editor->resize(480, 480); editor->show(); return app.exec(); }
// ------------------------------------------------------------------------- void ctkQImageView::keyPressEvent( QKeyEvent * event ) { Q_D( ctkQImageView ); if( d->SliceNumber >= 0 && d->SliceNumber < d->ImageList.size() ) { switch( event->key() ) { case Qt::Key_H: { QTextEdit * help = new QTextEdit(); help->setWindowFlags( Qt::Window ); help->setMinimumSize( 500, 500 ); help->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); help->setReadOnly( true ); help->append("<h1>CTK Simple Image Viewer Widget</h1>"); help->append("Contributed by: Kitware, Inc.<br>"); help->append("<h3>Keyboard commands:</h3>"); help->append(" <em>q</em> : quit"); help->append(" <em>h</em> : display this help"); help->append(" <em>i</em> : invert intensities"); help->append(" <em>[ ]</em> : increase / decrease zoom"); help->append(" <em>x y</em> : flip along the x / y axis"); help->append(" <em>r</em> : reset to initial conditions"); help->append(" <em>spacebar</em> : toggle continuous tracking of cursor"); help->append(" <em>up-arrow down-arrow</em> : change to next / previous slice"); help->append("<h3>Mouse commands:</h3>"); help->append(" <em>left-button</em> : window and level"); help->append(" <em>middle-button</em> : zoom"); help->append(" <em>right-button</em> : center"); help->show(); break; } case Qt::Key_Space: { d->Window->setMouseTracking( ! d->Window->hasMouseTracking() ); break; } case Qt::Key_X: { this->setFlipXAxis( ! this->flipXAxis() ); break; } case Qt::Key_Y: { this->setFlipYAxis( ! this->flipYAxis() ); break; } case Qt::Key_T: { this->setTransposeXY( ! this->transposeXY() ); break; } case Qt::Key_BracketRight: { this->setZoom( this->zoom() * 1.1 ); break; } case Qt::Key_BracketLeft: { this->setZoom( this->zoom() * 0.9 ); break; } case Qt::Key_I: { this->setInvertImage( ! this->invertImage() ); this->update( false, false ); break; } case Qt::Key_Q: { exit( EXIT_SUCCESS ); break; } case Qt::Key_R: { this->reset(); break; } case Qt::Key_Up: { this->setSliceNumber( d->SliceNumber+1 ); break; } case Qt::Key_Down: { this->setSliceNumber( d->SliceNumber-1 ); break; } default: { event->ignore(); } }; } }
void HtmlColorFactory::debugDisplay(QString& htmlTextRef) { QTextEdit* textEditPtr = new QTextEdit(); textEditPtr->setHtml(htmlTextRef); textEditPtr->show(); }