Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Fonctions  · 

Replacing the Print Dialog

[ Previous: Replacing the View Widget ] [ Home ] [ Next: Continuing Development ]

The Print dialog is the last component in our application that uses Motif. The current Print() function does nothing more than write the plain text to a temporary file, and then executes 'lpr' to send the text to the printer. Since we will use QPrinter, we do not this function any more, so we remove it. The current MainWindow::filePrint() implementation is removed as well. We will write a new MainWindow::filePrint() implementation in mainwindow.ui.h.

Note: The steps involved in using the QPrinter class are beyond the scope of this walkthrough and will not be discussed here. The QPrinter Class Reference, QSimpleRichText Class Reference and the Simple Application Walkthrough contain information on the use of QPrinter.

For completeness, the code to initialize a QPrinter object is included below.


Using Rich Text for Printing

Qt provides rich text using a subset of HTML. The QSimpleRichText class makes rich-text printing simple. All we need to do is create a string with the proper format tags inserted at the appropriate places. For our example, we will keep the printing output similar to previous versions.

First, we create the format tags that we will use.


Next we just loop over all pages, appending the page label, contents and formatting characters to a printtext variable (which is a QString).


The rest of the MainWindow::filePrint() function is the actual printing code. Here we simply create a QSimpleRichText object using the string we created above, and draw this string on the QPrinter object using QPainter.


Removing the Dependency on Xt/Motif

Our application no longer uses any Xt or Motif widgets. We can now finish removing the dependencies on Xt and Motif.

First, we cleanup the #include statements in mainwindow.ui.h.


The MainWindow::fileNew() function uses the Boolean and False keywords from the Xt library. C++ has these built into the language, so we use bool and false instead.

The last modification needed to completely remove Xt and Motif from our application is to stop using the QMotif class. We remove the qmotif.h #include statement from todo.cpp, and remove the instantiation from the main() function.

After doing this, we can remove the -lXm and -lqmotif from the LIBS variable in our project file. Our project file also contains source and headers for the the old custom Motif widgets previously used in our application. We remove these as well.

After regenerating the Makefile and building our project, we confirm that the application works correctly.

[ Previous: Replacing the View Widget ] [ Home ] [ Next: Continuing Development ]

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 94
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 42
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 6
Page suivante

Le Qt Labs au hasard

Logo

Le moteur de rendu OpenGL

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

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 !
 
 
 
 
Partenaires

Hébergement Web