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. Screenshot with QT
Forum Updated to NodeBB v4.3 + New Features

Screenshot with QT

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 320 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.
  • F Offline
    F Offline
    firsnur96
    wrote on last edited by
    #1

    Im using the code below for taking screenshot of my charts.
    But i dont want to open a file dialog.
    I want to save them with a giving format. In every new picture it will save it the date and time.
    I dont want to give a name.
    How can i do it without file dialog?

    ```
    QRect crop_rect(int x, int y, int w, int h);
    QPixmap desk = qApp->screens().at(0)->grabWindow(
        QDesktopWidget().winId());
    
       QString format = "jpg";
       QString initialPath = tr("Screenshots") + tr("/Image.") +
               QDateTime::currentDateTime().toString("dd.MM.yyyy" "hh.mm.ss.") + format;
    
       QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
                                  initialPath,
                                  tr("%1 Files (*.%2);;All Files (*)")
                                  .arg(format.toUpper())
                                  .arg(format));
       if (!fileName.isEmpty())
           desk.save(fileName, format.toLatin1().constData());
    
    jsulmJ Pablo J. RoginaP 2 Replies Last reply
    0
    • F firsnur96

      Im using the code below for taking screenshot of my charts.
      But i dont want to open a file dialog.
      I want to save them with a giving format. In every new picture it will save it the date and time.
      I dont want to give a name.
      How can i do it without file dialog?

      ```
      QRect crop_rect(int x, int y, int w, int h);
      QPixmap desk = qApp->screens().at(0)->grabWindow(
          QDesktopWidget().winId());
      
         QString format = "jpg";
         QString initialPath = tr("Screenshots") + tr("/Image.") +
                 QDateTime::currentDateTime().toString("dd.MM.yyyy" "hh.mm.ss.") + format;
      
         QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
                                    initialPath,
                                    tr("%1 Files (*.%2);;All Files (*)")
                                    .arg(format.toUpper())
                                    .arg(format));
         if (!fileName.isEmpty())
             desk.save(fileName, format.toLatin1().constData());
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @firsnur96 said in Screenshot with QT:

      But i dont want to open a file dialog

      Then don't open a dialog, what is the problem?
      Construct the file name as you need and use it...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      F 1 Reply Last reply
      2
      • jsulmJ jsulm

        @firsnur96 said in Screenshot with QT:

        But i dont want to open a file dialog

        Then don't open a dialog, what is the problem?
        Construct the file name as you need and use it...

        F Offline
        F Offline
        firsnur96
        wrote on last edited by
        #3

        @jsulm
        Ok.
        I want to add another push button for opening the directory
        How can i do?

        jsulmJ 1 Reply Last reply
        0
        • F firsnur96

          @jsulm
          Ok.
          I want to add another push button for opening the directory
          How can i do?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @firsnur96 said in Screenshot with QT:

          How can i do?

          Are you asking me how to add a button?
          Can you please explain what you want to do?
          Should there be a button to select folder where user can store screen-shots?
          What is the problem with that? Add a button, connect its clicked signal to a slot where you use https://doc.qt.io/qt-5/qfiledialog.html#getExistingDirectory to let the user select a folder, really nothing special...

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • F firsnur96

            Im using the code below for taking screenshot of my charts.
            But i dont want to open a file dialog.
            I want to save them with a giving format. In every new picture it will save it the date and time.
            I dont want to give a name.
            How can i do it without file dialog?

            ```
            QRect crop_rect(int x, int y, int w, int h);
            QPixmap desk = qApp->screens().at(0)->grabWindow(
                QDesktopWidget().winId());
            
               QString format = "jpg";
               QString initialPath = tr("Screenshots") + tr("/Image.") +
                       QDateTime::currentDateTime().toString("dd.MM.yyyy" "hh.mm.ss.") + format;
            
               QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
                                          initialPath,
                                          tr("%1 Files (*.%2);;All Files (*)")
                                          .arg(format.toUpper())
                                          .arg(format));
               if (!fileName.isEmpty())
                   desk.save(fileName, format.toLatin1().constData());
            
            Pablo J. RoginaP Offline
            Pablo J. RoginaP Offline
            Pablo J. Rogina
            wrote on last edited by Pablo J. Rogina
            #5

            @firsnur96 please don't double post

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            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