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. Instantiate QWidget in QCoreApplication

Instantiate QWidget in QCoreApplication

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 2.6k Views
  • 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.
  • R Offline
    R Offline
    rrk13
    wrote on last edited by
    #1

    Is there any way I can instantiate a QWidget in a QCoreApplication? I do not want to show this widget, but just want to paint the widget to a png. I need to instantiate the widget, and then call QPixmap::grabWidget().

    I cannot change this from QCoreApplication to QApplication. Are there any other ideas?

    1 Reply Last reply
    0
    • UndeadBlowU Offline
      UndeadBlowU Offline
      UndeadBlow
      wrote on last edited by
      #2

      Hello. There is no way, as I know, to instantiate QWidget in QCoreApplication, but you can grab hidden widget without show that.
      Code and it's execution for example:
      @#include <QtGui>

      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);
      QLabel *hello = new QLabel("Hello Qt Forum!");
      QPixmap m = QPixmap::grabWidget(hello);
      m.save("C:\Users\1\Desktop\1.png", "png");
      return a.exec();
      }@
      Result:
      !http://s43.radikal.ru/i099/1304/8e/1dd6fcff3b1e.png!

      1 Reply Last reply
      0
      • U Offline
        U Offline
        utcenter
        wrote on last edited by
        #3

        I don't think QCoreApplication provides the functionality needed to maintain a GUI. Technically it is possible to draw any widget on an off-screen surface but I don't know if that is possible without a QApplication.

        1 Reply Last reply
        0
        • podsvirovP Offline
          podsvirovP Offline
          podsvirov
          wrote on last edited by
          #4

          Your application uses the Gui module in any case (class QPixmap for example).
          Use the code above, but just do not show widgets.

          bq. Code and it’s execution for example:
          @
          #include <QtGui>
          int main(int argc, char *argv[])
          {
          QApplication a(argc, argv);
          QLabel *hello = new QLabel("Hello Qt Forum!");
          QPixmap m = QPixmap::grabWidget(hello);
          m.save("C:\Users\1\Desktop\1.png", "png");
          return a.exec();
          }
          @

          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