Logo ROOT   6.10/09
Reference Guide
QtPrintDialog.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_gui
3 /// This is a small ROOT macro to use Qt 3.3 class: [QPrinter](https://doc.qt.io/archives/3.3/qprinter.html)
4 /// to setup the printer via Qt "setup printer dialog"
5 /// See: [Printer setup dialog box](https://doc.qt.io/archives/3.3/qprinter.html#setup)
6 /// and print out the ROOT TCanvas object either via the "can" pointer provided or the current one.
7 ///
8 /// To use, invoke ACLiC from the ROOT prompt:
9 /// ~~~
10 /// root [] .x QtPrintDialog.C++
11 /// ~~~
12 ///
13 /// To use it with no ACLiC, omit the trailing "++"
14 /// ~~~
15 /// root [] .x QtPrintDialog.C
16 /// ~~~
17 ///
18 /// The full list of the Qt classes available from Cint is defined by
19 /// [by $ROOTSYS/cint/lib/qtclasses.h](http://root.bnl.gov/QtRoot/htmldoc/src/qtclasses.h.html)
20 ///
21 /// All Qt classes can be used from ACLiC though.
22 ///
23 /// \macro_code
24 ///
25 /// \author Valeri Fine 23/03/2006
26 
27 
28 # include <QPrintDialog>
29 # include <QPrinter>
30 # include <QPainter>
31 # include <QPixmap>
32 # include <TCanvas.h>
33 # include <TGQt.h>
34 
35 void QtPrintDialog(TVirtualPad *pad = 0) {
36 
37  TVirtualPad *pd = pad;
38  if (!pd) pd = TPad::Pad(); // ->GetCanvas();
39  if (pd) {
40  QPrinter p;
41  // Open the Qt "Setup Printer" dialog to configure the "QPrinter p" object
42  QPrintDialog printDialog(&p);
43  if (printDialog.exec() == QDialog::Accepted) {
44  Int_t id = pd->GetPixmapID();
45  QPixmap *pix = (QPixmap *)(TGQt::iwid(id));
46  QPainter pnt(&p);
47  pnt.drawPixmap(0,0,*pix);
48  }
49  } else {
50  printf(" No TCanvas has been selected yet! \n");
51  }
52 }
53 
int Int_t
Definition: RtypesCore.h:41
static TVirtualPad *& Pad()
Return the current pad for the current thread.
Definition: TVirtualPad.cxx:32
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:49
virtual Int_t GetPixmapID() const =0