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 = new QTextEdit; //! [0] QTextDocument *document = editor->document(); QTextCursor redCursor(document); //! [0] //! [1] QTextCursor blueCursor(document); //! [1] QTextCharFormat redFormat(redCursor.charFormat()); redFormat.setForeground(Qt::red); QTextCharFormat blueFormat(blueCursor.charFormat()); blueFormat.setForeground(Qt::blue); redCursor.setCharFormat(redFormat); blueCursor.setCharFormat(blueFormat); for (int i = 0; i < 20; ++i) { if (i % 2 == 0) redCursor.insertText(tr("%1 ").arg(i), redFormat); if (i % 5 == 0) blueCursor.insertText(tr("%1 ").arg(i), blueFormat); } editor->setWindowTitle(tr("Text Document Cursors")); editor->resize(320, 480); editor->show(); return app.exec(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QTextEdit *editor = new QTextEdit; //! [0] QTextDocument *document = new QTextDocument(editor); QTextCursor cursor(document); //! [0] //! [1] QTextImageFormat imageFormat; imageFormat.setName(":/images/advert.png"); cursor.insertImage(imageFormat); //! [1] cursor.insertBlock(); cursor.insertText("Code less. Create more."); editor->setDocument(document); editor->setWindowTitle(tr("Text Document Images")); editor->resize(320, 480); editor->show(); 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(); }
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 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(); }
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 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(); }