Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Print Preview features fails on Windows 10
Forum Updated to NodeBB v4.3 + New Features

Print Preview features fails on Windows 10

Scheduled Pinned Locked Moved Unsolved General and Desktop
qprintpreviewwiwindows10
19 Posts 3 Posters 6.0k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N NIXIN
    20 Mar 2017, 12:24

    @mrjj
    Hi,
    I have developed a sample application which gives the same problem

    widget.h

    #ifndef WIDGET_H
    #define WIDGET_H

    #include <QWidget>
    #include <Qpainter>

    namespace Ui {
    class Widget;
    }

    class Widget : public QWidget
    {
    Q_OBJECT

    public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

    private slots:
    void on_pushButton_clicked();

    private:
    Ui::Widget *ui;
    };

    #endif // WIDGET_H

    widget.cpp

    #include "widget.h"
    #include "ui_widget.h"
    #include "testdialog.h"

    Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
    {
    ui->setupUi(this);
    }

    Widget::~Widget()
    {
    delete ui;
    }

    void Widget::on_pushButton_clicked()
    {
    TestDialog dlg;
    dlg.printPreview();
    dlg.exec();
    }

    testdialog.h

    #ifndef TESTDIALOG_H
    #define TESTDIALOG_H

    #include <QDialog>
    #include <QPainter>
    #include <QPrintPreviewWidget>
    #include <QPrinter>
    #include <QDebug>

    namespace Ui {
    class TestDialog;
    }

    class TestDialog : public QDialog
    {
    Q_OBJECT

    public:
    explicit TestDialog(QWidget *parent = 0);
    ~TestDialog();

    void printPreview();
    

    public slots:
    void slot_print(QPrinter *printer);

    private:
    Ui::TestDialog ui;
    QPrintPreviewWidget
    printPreviewWidget;
    QPrinter printer;
    };

    #endif // TESTDIALOG_H

    testdialog.cpp

    #include "testdialog.h"
    #include "ui_testdialog.h"

    TestDialog::TestDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::TestDialog)
    {
    ui->setupUi(this);

    setWindowFlags(Qt::Window);
    //printPreviewWidget = NULL;
    

    }

    TestDialog::~TestDialog()
    {
    delete ui;
    }

    void TestDialog::printPreview()
    {
    printPreviewWidget = new QPrintPreviewWidget(&printer, this);

    connect(printPreviewWidget, SIGNAL(paintRequested(QPrinter*)), this, SLOT(slot_print(QPrinter*)));
    
    ui->gridLayout->addWidget(printPreviewWidget);
    

    }

    void TestDialog::slot_print(QPrinter *printer)
    {
    QPainter painterForPrint(printer);

    int viewPortWidth = painterForPrint.viewport().width();
    int viewPortHeight = painterForPrint.viewport().height();

    qDebug() << "View Port Width: " << viewPortWidth;
    qDebug() << "View Port Height: " << viewPortHeight;
    }

    main.cpp

    #include "widget.h"
    #include <QApplication>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    Widget w;
    w.show();

    return a.exec();
    

    }

    I got the following error on windows 10:

    QWin32PrintEngine::initialize: CreteDC failed (The specified procedure could not be found.)

    I am getting viewport dimensions as zero.

    Whereas on Windows 7, I don't get any such error and also, I got a valid view port dimensions.

    K Offline
    K Offline
    kenchan
    wrote on 20 Mar 2017, 13:10 last edited by
    #7

    @NIXIN
    OK, I built your sample and got it working without any errors.
    You have a couple of issues with that code but I guess they are just typos.

    Ui::TestDialog ui; needs to be a pointer -> Ui::TestDialog *ui;
    QPrintPreviewWidget printPreviewWidget; needs to be a pointer -> QPrintPreviewWidget *printPreviewWidget;

    1 Reply Last reply
    2
    • N Offline
      N Offline
      NIXIN
      wrote on 20 Mar 2017, 13:47 last edited by
      #8

      @kenchan

      Hi,
      Thanks for reverting back, but the errors which you pointed are pointers. I checked in my code, those are pointers.

      Actually I have directly copied and pasted the code to this editor, may be due to that some modifications had taken place.

      However, What values of 'View Port Width' and 'View Port Height' you got??

      K 1 Reply Last reply 20 Mar 2017, 13:49
      0
      • N NIXIN
        20 Mar 2017, 13:47

        @kenchan

        Hi,
        Thanks for reverting back, but the errors which you pointed are pointers. I checked in my code, those are pointers.

        Actually I have directly copied and pasted the code to this editor, may be due to that some modifications had taken place.

        However, What values of 'View Port Width' and 'View Port Height' you got??

        K Offline
        K Offline
        kenchan
        wrote on 20 Mar 2017, 13:49 last edited by
        #9

        @NIXIN
        View Port Width: 1101
        View Port Height: 771

        1 Reply Last reply
        0
        • N Offline
          N Offline
          NIXIN
          wrote on 20 Mar 2017, 13:55 last edited by
          #10

          @kenchan
          Did you tried on Windows 10??

          K 1 Reply Last reply 20 Mar 2017, 13:56
          0
          • N NIXIN
            20 Mar 2017, 13:55

            @kenchan
            Did you tried on Windows 10??

            K Offline
            K Offline
            kenchan
            wrote on 20 Mar 2017, 13:56 last edited by
            #11

            @NIXIN
            yes, Windows 10 64bit Qt 5.6.0

            1 Reply Last reply
            0
            • N Offline
              N Offline
              NIXIN
              wrote on 20 Mar 2017, 13:57 last edited by
              #12

              @kenchan

              But for me its not working....

              M K 2 Replies Last reply 20 Mar 2017, 13:58
              0
              • N NIXIN
                20 Mar 2017, 13:57

                @kenchan

                But for me its not working....

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 20 Mar 2017, 13:58 last edited by
                #13

                @NIXIN
                are you sure you have a default printer?

                1 Reply Last reply
                0
                • N NIXIN
                  20 Mar 2017, 13:57

                  @kenchan

                  But for me its not working....

                  K Offline
                  K Offline
                  kenchan
                  wrote on 20 Mar 2017, 14:00 last edited by
                  #14

                  @NIXIN
                  there must be something wrong with your QT installation, project settings or your runtime env??

                  Are you using the Microsoft compiler or something else?

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    NIXIN
                    wrote on 20 Mar 2017, 14:01 last edited by
                    #15

                    I have cute PDF writer....

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      NIXIN
                      wrote on 20 Mar 2017, 14:02 last edited by
                      #16

                      @kenchan
                      I am using mingw32bit...

                      K 1 Reply Last reply 20 Mar 2017, 14:03
                      0
                      • N NIXIN
                        20 Mar 2017, 14:02

                        @kenchan
                        I am using mingw32bit...

                        K Offline
                        K Offline
                        kenchan
                        wrote on 20 Mar 2017, 14:03 last edited by
                        #17

                        @NIXIN
                        I have never used it so I can't offer you any advice on that.

                        1 Reply Last reply
                        0
                        • N Offline
                          N Offline
                          NIXIN
                          wrote on 21 Mar 2017, 05:39 last edited by
                          #18

                          @kenchan
                          Are you using qt-opensource-windows-x86-msvc2015_64-5.6.0.exe installation ?

                          K 1 Reply Last reply 21 Mar 2017, 06:05
                          0
                          • N NIXIN
                            21 Mar 2017, 05:39

                            @kenchan
                            Are you using qt-opensource-windows-x86-msvc2015_64-5.6.0.exe installation ?

                            K Offline
                            K Offline
                            kenchan
                            wrote on 21 Mar 2017, 06:05 last edited by
                            #19

                            @NIXIN
                            I am currently using qt-opensource-windows-x86-msvc2013_64-5.6.0

                            1 Reply Last reply
                            0

                            16/19

                            20 Mar 2017, 14:02

                            • Login

                            • Login or register to search.
                            16 out of 19
                            • First post
                              16/19
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved