RichtextIn this example we demonstrate how to display rich text in a widget. To do this some sayings taken from the famous Unix "fortune" are displayed nicely formatted.
Header file:
/**************************************************************************** ** $Id: qt/richtext.h 3.3.7 edited Aug 31 2005 $ ** ** Copyright (C) 1992-2005 Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #ifndef RICHTEXT_H #define RICHTEXT_H #include <qvbox.h> class QTextView; class QPushButton; class MyRichText : public QVBox { Q_OBJECT public: MyRichText( QWidget *parent = 0, const char *name = 0 ); protected: QTextView *view; QPushButton *bClose, *bNext, *bPrev; int num; protected slots: void prev(); void next(); }; #endif
Implementation:
/**************************************************************************** ** $Id: qt/richtext.cpp 3.3.7 edited Aug 31 2005 $ ** ** Copyright (C) 1992-2005 Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #include "richtext.h" #include <qhbox.h> #include <qhbox.h> #include <qpushbutton.h> #include <qtextview.h> #include <qbrush.h> #include <qapplication.h> static const char* sayings[] = { "<b>Saying 1:</b><br>" "<hr><br><br>" "<big>Evil is that which one believes of others. It is a sin to believe evil " "of others, but it is seldom a mistake.</big><br><br>" "<center><i>-- H.L. Mencken</i></center>", "<b>Saying 2:</b><br>" "<hr><br><br>" "<big>A well-used door needs no oil on its hinges.<br>" "A swift-flowing steam does not grow stagnant.<br>" "Neither sound nor thoughts can travel through a vacuum.<br>" "Software rots if not used.<br><br>" "These are great mysteries.</big><br><br>" "<center><i>-- Geoffrey James, \"The Tao of Programming\"</i></center>", "<b>Saying 3:</b><br>" "<hr><br><br>" "<big>Show business is just like high school, except you get paid.</big><br><br>" "<center><i>-- Martin Mull</i></center>", "<b>Saying 4:</b><br>" "<hr><br><br>" "<big><b>The Least Successful Executions</b><br>" "<twocolumn><p> History has furnished us with two executioners worthy of attention. " "The first performed in Sydney in Australia. In 1803 three attempts were " "made to hang a Mr. Joseph Samuels. On the first two of these the rope " "snapped, while on the third Mr. Samuels just hung there peacefully until he " "and everyone else got bored. Since he had proved unsusceptible to capital " "punishment, he was reprieved.</p>" "<p> The most important British executioner was Mr. James Berry who " "tried three times in 1885 to hang Mr. John Lee at Exeter Jail, but on each " "occasion failed to get the trap door open.<!p>" "<p> In recognition of this achievement, the Home Secretary commuted " "Lee's sentence to \"life\" imprisonment. He was released in 1917, emigrated " "to America and lived until 1933.</p></twocolumn></big><br><br>" "<center><i>-- Stephen Pile, \"The Book of Heroic Failures\"</i></center>", "<b>Saying 5:</b><br>" "<hr><br><br>" "<big>If you can, help others. If you can't, at least don't hurt others.</big><br><br>" "<center><i>-- the Dalai Lama</i></center>", "<b>Saying 6:</b><br>" "<hr><br><br>" "<big>Television has brought back murder into the home -- where it belongs.</big><br><br>" "<center><i>-- Alfred Hitchcock</i></center>", "<b>Saying 7:</b><br>" "<hr><br><br>" "<big>I don't know who my grandfather was; I am much more concerned to know " "what his grandson will be.</big><br><br>" "<center><i>-- Abraham Lincoln</i></center>", 0 };
Main:
/**************************************************************************** ** $Id: qt/main.cpp 3.3.7 edited Aug 31 2005 $ ** ** Copyright (C) 1992-2005 Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #include "richtext.h" #include <qapplication.h> int main( int argc, char **argv ) { QApplication a( argc, argv ); MyRichText richtext; richtext.resize( 450, 350 ); richtext.setCaption( "Qt Example - Richtext" ); a.setMainWidget( &richtext ); richtext.show(); return a.exec(); } See also Examples. |
Publicité
Best OfActualités les plus luesSemaine
Mois
Année
Le Qt Developer Network au hasardLivre blanc de l'outillage de Qt QuickLe Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.
CommunautéRessources
Liens utilesContact
Qt dans le magazine |
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 3.3 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com