Results 1 to 11 of 11

Thread: Ensuring a Widget Is Hidden

  1. #1
    Join Date
    Jan 2009
    Location
    Camp Lejeune, NC
    Posts
    24
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Ensuring a Widget Is Hidden

    I'm making a little screenshot program that runs in the system tray. You click the tray icon, and a menu pops up. You click on "Copy to Clipboard" and the screenshot is sent to the clipboard. The only problem is, that menu is still visible. Is there anyway to work around this that doesn't involve a disgusting hack (timer, threading, etc...)?
    Lenovo ThinkPad T400 - Gentoo Linux 2008.0 Hardened
    Apple iBook G3 - Gentoo Linux 2008.0 Desktop
    Linksys WRT54GL - OpenWrt Kamikaze
    Linksys WRT310N - Stock Crap

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Ensuring a Widget Is Hidden

    You can call hide() on the menu and afterwards call QCoreApplication::sendPostedEvents() on the menu. Afterwards you should be able to make the screenshot.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2009
    Location
    Camp Lejeune, NC
    Posts
    24
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Ensuring a Widget Is Hidden

    It's still not working. I've uploaded the source files to http://www.wswartzendruber.net/uploa...screenshooter/. The file in question is systemtrayiconmanager.cpp at line 110.

    I've tried:

    Qt Code:
    1. QCoreApplication::processEvents()
    2.  
    3.  
    4. while (application->hasPendingEvents())
    5. QCoreApplication::processEvents(QEventLoop::AllEvents);
    6.  
    7. while (application->hasPendingEvents())
    8. QCoreApplication::flush();
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 14th May 2009 at 19:44.
    Lenovo ThinkPad T400 - Gentoo Linux 2008.0 Hardened
    Apple iBook G3 - Gentoo Linux 2008.0 Desktop
    Linksys WRT54GL - OpenWrt Kamikaze
    Linksys WRT310N - Stock Crap

  4. #4
    Join Date
    Apr 2008
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Ensuring a Widget Is Hidden

    Should really use code tags above

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Ensuring a Widget Is Hidden

    But where did you put those lines? Did you do as I told you to?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jan 2009
    Location
    Camp Lejeune, NC
    Posts
    24
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Ensuring a Widget Is Hidden

    Quote Originally Posted by wysota View Post
    But where did you put those lines? Did you do as I told you to?
    I did try send posted events. I put all that stuff right above the aformentioned line in the aformentioned file.
    Lenovo ThinkPad T400 - Gentoo Linux 2008.0 Hardened
    Apple iBook G3 - Gentoo Linux 2008.0 Desktop
    Linksys WRT54GL - OpenWrt Kamikaze
    Linksys WRT310N - Stock Crap

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Ensuring a Widget Is Hidden

    What exactly did you put there?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jan 2009
    Location
    Camp Lejeune, NC
    Posts
    24
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Ensuring a Widget Is Hidden

    Quote Originally Posted by wysota View Post
    What exactly did you put there?
    Qt Code:
    1. void SystemTrayIconManager::copyToClipboardTriggered()
    2. {
    3. // I put those lines included in one of my previous posts here.
    4.  
    5. cout << "Screenshot taken." << endl;
    6.  
    7. application->clipboard()->setPixmap(getScreenshotPixmap());
    8. }
    To copy to clipboard, switch view to plain text mode 
    I didn't put them in all at the same time, but one at a time.
    Lenovo ThinkPad T400 - Gentoo Linux 2008.0 Hardened
    Apple iBook G3 - Gentoo Linux 2008.0 Desktop
    Linksys WRT54GL - OpenWrt Kamikaze
    Linksys WRT310N - Stock Crap

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Ensuring a Widget Is Hidden

    But did you hide the menu before putting some event processing related code?

    This works fine for me:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class ShotButton : public QPushButton {
    4. Q_OBJECT
    5. public:
    6. ShotButton() : QPushButton(){
    7. setText("Take a shot");
    8. connect(this, SIGNAL(clicked()), this, SLOT(makeAShot()));
    9. }
    10. private slots:
    11. void makeAShot(){
    12. hide();
    13. QCoreApplication::sendPostedEvents();
    14. QPixmap px = QPixmap::grabWindow(QApplication::desktop()->winId());
    15. show();
    16. px.save("/tmp/pixmap.jpg");
    17. }
    18. };
    19.  
    20. #include "main.moc"
    21.  
    22. int main(int argc, char **argv){
    23. QApplication app(argc, argv);
    24. ShotButton button;
    25. button.show();
    26. return app.exec();
    27. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 14th May 2009 at 22:33.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Jan 2009
    Location
    Camp Lejeune, NC
    Posts
    24
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Ensuring a Widget Is Hidden

    Hmmm... Works on Windows, but not X11.
    Lenovo ThinkPad T400 - Gentoo Linux 2008.0 Hardened
    Apple iBook G3 - Gentoo Linux 2008.0 Desktop
    Linksys WRT54GL - OpenWrt Kamikaze
    Linksys WRT310N - Stock Crap

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Ensuring a Widget Is Hidden

    I'm working on X11, so it works there as well...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. Playbutton functionality
    By uchennaanyanwu in forum Qt Programming
    Replies: 5
    Last Post: 31st July 2008, 22:29
  3. How to Open & Close a Widget ?!!
    By Fatla in forum Qt Programming
    Replies: 6
    Last Post: 13th June 2008, 20:39
  4. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  5. closing dialog in hidden main Widget
    By Lele in forum Qt Programming
    Replies: 3
    Last Post: 6th December 2006, 10:35

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.