Results 1 to 8 of 8

Thread: grabeWidget & QTabWidget problem

  1. #1
    Join Date
    Apr 2007
    Posts
    5
    Thanks
    3
    Qt products
    Qt3
    Platforms
    Windows

    Question grabeWidget & QTabWidget problem

    Hello, guys,

    Very glad to be here. This is my first post.

    I recently have a problem with saving my application interface (some X-Y charts) to PNG files using QPixmap::grabWidget and QTabWidget. My chart is drawn on a QwtPlot object in the pages of a QTabWidget object. And I have 9 pages totally. I want each single page be saved automatically to a PNG file for later review (no button press, mouse click etc.). The files are saved, but some components of the chart are missing (looks like the chart is not done yet, so I put Sleep(500) in there). I tried grabWindow(), but since the pages of the QTabWidget are not visible at this moment of time, so I can not get what I want. I am using QT 3.3.6 and Qwt 4.2 and MSVS 2005.

    I attach some of my codes, hope someone can help me out. Thanks in advance.

    for(int i = 8; i>=0; i--)
    {
    s_tab_view->setCurrentPage(i); // s_tab_view: QTabView
    QPixmap peakPixmap;
    QString pixMapFileName = "C:\\pinPostDoc\\" + dateQString + "_" +
    s_tab_view->label(i).remove('&') + ".png";
    Sleep(500);
    peakPixmap = QPixmap::grabWidget(s_tab_view, 0, 0, -1, -1);
    beakPixmap.save(pixMapFileName, "PNG");
    }
    Last edited by conglu; 20th April 2007 at 18:01.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: grabeWidget & QTabWidget problem

    Why don't you try synchronizing the chart creation with grabWidget(). Can't you emit a signal or set a flag somewhere to indicate that a certain chart has been finished and can be saved?

    Regards

  3. The following user says thank you to marcel for this useful post:

    conglu (23rd April 2007)

  4. #3
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: grabeWidget & QTabWidget problem

    Perhaps it is a problem with Qt3s limitations, have you tried using Qt4?

  5. The following user says thank you to VireX for this useful post:

    conglu (23rd April 2007)

  6. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,313
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: grabeWidget & QTabWidget problem

    This is not really an answer to your question, but note that grabWidget is a suboptimal way to save plots. Better use QwtPlot::print(QPaintDevice&, ...) instead.

    QwtPlot::print renders the plot to any rect in the resolution of your paint device + you can save it as vector graphics (f.e. Postscript, PDF, SVG). If you render to a QPrinter you can have Encapsulated Postscript with a much higher precision than on screen. If you render to a QPixmep you can have any format supported by QImageIO and if you render to a QPicture you can even have SVG. ( With Qt4 you can also render to PDF. )

    Uwe

  7. The following user says thank you to Uwe for this useful post:

    conglu (23rd April 2007)

  8. #5
    Join Date
    Apr 2007
    Posts
    5
    Thanks
    3
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: grabeWidget & QTabWidget problem

    Quote Originally Posted by marcel View Post
    Why don't you try synchronizing the chart creation with grabWidget(). Can't you emit a signal or set a flag somewhere to indicate that a certain chart has been finished and can be saved?

    Regards
    I used a QTimer to activate a "slot" to print these pictures, but the components were still missing. Actually, I tried QTimer::start(), singleShot(), and even QThread. All same result.

    Maybe this is a limitation of QT3.x just like VireX said. But anyone can comfirm it?

    Seems I may need to go up to QT4.

    Thanks again, guys.

  9. #6
    Join Date
    Apr 2007
    Posts
    5
    Thanks
    3
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: grabeWidget & QTabWidget problem

    I find a way to solve this problem. Before the charts are created, show every single tab manually. Then everything is all right. My thought is that the prblem maybe caused by QwtPlot instead of QPixmap.

  10. #7
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,313
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: grabeWidget & QTabWidget problem

    Neither QPixmap nor QwtPlot: you can't grab something that is not already there.

    1) The geometry of the plot is triggered by resize events. I haven't checked it myself, but I expect that a plot, that is on a hidden tab, that has never been shown, never got one.

    2) The content of the plot is rendered by QwtPlot::replot. If you don't call it manually and autoReplot is off, the first replot is done in QwtPlot::polish, what is also not called, if the tab has not been shown once.

    So I recommend to call QwtPlot::replot manually (after construction) and again, use QwtPlot::print, that doesn't need resizeEvents and is the better solution anyway.

    HTH,
    Uwe

  11. #8
    Join Date
    Apr 2007
    Posts
    5
    Thanks
    3
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: grabeWidget & QTabWidget problem

    Quote Originally Posted by Uwe View Post
    Neither QPixmap nor QwtPlot: you can't grab something that is not already there.

    1) The geometry of the plot is triggered by resize events. I haven't checked it myself, but I expect that a plot, that is on a hidden tab, that has never been shown, never got one.
    The images are there. I got them using the same code for the replay of a single data file. But after I tried to apply my application to multi data files, the code stops working. Since the QTimer event does not run until the FOR loop for multi-file stops.

    2) The content of the plot is rendered by QwtPlot::replot. If you don't call it manually and autoReplot is off, the first replot is done in QwtPlot:olish, what is also not called, if the tab has not been shown once.
    I called QwtPlot::replot(), polish(), and QTabWidget::showPage() before printing a tab. None of them works.

    So I recommend to call QwtPlot::replot manually (after construction) and again, use QwtPlot:rint, that doesn't need resizeEvents and is the better solution anyway.

    HTH,
    Uwe
    I am going to try QwtPlot:rint(), and let you guys know what will happen.

    Thanks again.

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.