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
Qt 6.11 is out! See what's new in the release blog

QCustomPlot didnt show under Windows

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 2 Posters 7.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 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
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #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 last edited by A Former User
        #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
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on 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 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
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #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 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.

                mrjjM 1 Reply Last reply
                0
                • ? A Former User

                  @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.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #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 last edited by
                    #10

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

                    mrjjM 1 Reply Last reply
                    1
                    • ? A Former User

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

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 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 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.

                        mrjjM 1 Reply Last reply
                        0
                        • ? A Former User

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

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 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 last edited by
                            #14

                            ok much thanks to you.

                            mrjjM 1 Reply Last reply
                            1
                            • ? A Former User

                              ok much thanks to you.

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #15

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

                              1 Reply Last reply
                              0

                              • Login

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