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. QCustomPlot didnt show under Windows
Forum Updated to NodeBB v4.3 + New Features

QCustomPlot didnt show under Windows

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 2 Posters 3.9k Views 1 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on 2 Jun 2016, 12:37 last edited by
    #2

    Please. Nobody can help? Any ideas? If i want to draw something in printPreview the page is always blank.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 2 Jun 2016, 12:41 last edited by mrjj 6 Feb 2016, 12:41
      #3

      Hi
      did u install printer in windows?

      Else try CustomPlot forum. they might know if issues in windows.

      1 Reply Last reply
      1
      • ? Offline
        ? Offline
        A Former User
        wrote on 2 Jun 2016, 13:48 last edited by A Former User 6 Feb 2016, 13:49
        #4

        no i have only a pdf printer installed. is it necessary? But i can print Text in another function with QPainter to the Device.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 2 Jun 2016, 14:19 last edited by
          #5

          well a pdf printer should be just as good.
          if you render some other widget, then it works?

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on 2 Jun 2016, 14:32 last edited by
            #6

            I tried to paint something else, but he dont paint anything on the page.

            void MainWindow::printPreview(QPrinter *printer)
            {
                //ui->customPlotWidget->render(printer);
                QPainter painter(printer);
                painter.drawText(QPoint(50, 50), "12");
                painter.end();
            }
            
            1 Reply Last reply
            0
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 2 Jun 2016, 14:40 last edited by mrjj 6 Feb 2016, 14:42
              #7

              so its not related to customplot :)
              Code seems fine at first sight. not sure why.
              you dont need a
              painter.begin(&printer); ?

              also is 50,50 inside the visible page?
              maybe try
              painter.drawText(QPoint(450, 450), "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

              1 Reply Last reply
              1
              • ? Offline
                ? Offline
                A Former User
                wrote on 2 Jun 2016, 14:47 last edited by
                #8

                @mrjj said:

                painter.drawText(QPoint(450, 450), "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

                ok this works. so it could be the customplot widget. perhaps i need to ask in the customplot forum then. I tried now that

                void MainWindow::printPreview(QPrinter *printer)
                {
                    //ui->customPlotWidget->render(printer);
                    QPainter painter;
                    painter.begin(printer);
                    ui->customPlotWidget->render(&painter);
                    painter.end();
                }
                

                but this didnt work too.

                M 1 Reply Last reply 2 Jun 2016, 14:49
                0
                • ? A Former User
                  2 Jun 2016, 14:47

                  @mrjj said:

                  painter.drawText(QPoint(450, 450), "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

                  ok this works. so it could be the customplot widget. perhaps i need to ask in the customplot forum then. I tried now that

                  void MainWindow::printPreview(QPrinter *printer)
                  {
                      //ui->customPlotWidget->render(printer);
                      QPainter painter;
                      painter.begin(printer);
                      ui->customPlotWidget->render(&painter);
                      painter.end();
                  }
                  

                  but this didnt work too.

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 2 Jun 2016, 14:49 last edited by mrjj 6 Feb 2016, 14:50
                  #9

                  @Fuel
                  Ok, so text was just outside:)
                  hi
                  maybe it just really, really small and outside area?
                  Normally u scale the widgets. as screen and printer have very different DPI

                         QPainter painter;
                          painter.begin(&printer);
                          double xscale = printer.pageRect().width()/double(myWidget->width());
                          double yscale = printer.pageRect().height()/double(myWidget->height());
                          double scale = qMin(xscale, yscale);
                          painter.translate(printer.paperRect().x() + printer.pageRect().width()/2,
                                             printer.paperRect().y() + printer.pageRect().height()/2);
                          painter.scale(scale, scale);
                          painter.translate(-width()/2, -height()/2);
                  
                          myWidget->render(&painter);
                  
                  1 Reply Last reply
                  1
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on 2 Jun 2016, 15:01 last edited by
                    #10

                    omg yes that works. but why i need to do that with windows? hmm dont really understand that.

                    M 1 Reply Last reply 2 Jun 2016, 15:04
                    1
                    • ? A Former User
                      2 Jun 2016, 15:01

                      omg yes that works. but why i need to do that with windows? hmm dont really understand that.

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 2 Jun 2016, 15:04 last edited by
                      #11

                      @Fuel
                      Ok, so was just super small :)

                      well if same printer in linux & windows then
                      makes little sense. :)

                      Else it just a matter of DPI.

                      1 Reply Last reply
                      0
                      • ? Offline
                        ? Offline
                        A Former User
                        wrote on 2 Jun 2016, 15:15 last edited by
                        #12

                        so different printer with different dpi would change the size? how can i prevent that? I always want the Fullsize on one page.

                        M 1 Reply Last reply 2 Jun 2016, 15:33
                        0
                        • ? A Former User
                          2 Jun 2016, 15:15

                          so different printer with different dpi would change the size? how can i prevent that? I always want the Fullsize on one page.

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 2 Jun 2016, 15:33 last edited by
                          #13

                          @Fuel
                          Yes, DPI means how many small dots/pixels pr inch.
                          A screen has may 72
                          and printer might have 1200
                          that is why we scale it.
                          So a widget that is 400 pixels will be extremely small on printer with high DPI.

                          so you must always scale it.
                          If use use the sample code. it will always be same size.

                          1 Reply Last reply
                          2
                          • ? Offline
                            ? Offline
                            A Former User
                            wrote on 2 Jun 2016, 15:39 last edited by
                            #14

                            ok much thanks to you.

                            M 1 Reply Last reply 2 Jun 2016, 15:46
                            1
                            • ? A Former User
                              2 Jun 2016, 15:39

                              ok much thanks to you.

                              M Offline
                              M Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 2 Jun 2016, 15:46 last edited by
                              #15

                              @Fuel
                              you are most welcome.
                              Please mark as solved :)

                              1 Reply Last reply
                              0

                              11/15

                              2 Jun 2016, 15:04

                              • Login

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