Results 1 to 6 of 6

Thread: Qt3 to Qt4 transition, setWindowIcon() problems

  1. #1
    Join Date
    Dec 2007
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Qt3 to Qt4 transition, setWindowIcon() problems

    I'm making the transition from Qt 3 to Qt 4.3.2 and I'm having trouble with QMainWindow's icon (the icon in the upper left corner in the Windows title bar and in the Windows taskbar) being displayed correctly. I'm using Exceed as a window manager and it's not displaying the colors correctly - the icon's shape is right but the colors are the background and foreground colors chosen in Exceed (and not those of the icon itself).

    I'm bringing this up here because this all worked correctly in Qt 3.3. I'm not very familiar with Qt's drawing internals - does anyone know what they changed in the way they set the main window icon between Qt 3 and Qt 4 that might cause this? (Maybe an endian issue...?)

    I know I'm grasping at straws here, but any hints would be greatly appreciated. The people at Exceed are saying it's a Qt issue, so I'm SOL until I can (hopefully) bring something back to them. Thanks for your time.

  2. #2
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    63
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Qt3 to Qt4 transition, setWindowIcon() problems

    There is another mechanism of initialization widgets in Qt4. Could you post problem codes of initialization of QMainWindow ?
    Best regards,
    Yuriy Rusinov.

  3. #3
    Join Date
    Dec 2007
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt3 to Qt4 transition, setWindowIcon() problems

    This code will cause the problems that I'm seeing:

    main.cpp:

    Qt Code:
    1. #include <qapplication.h>
    2. #include "testUi.h"
    3.  
    4. int main( int argc, char ** argv )
    5. {
    6. QApplication app( argc, argv );
    7. Ui::TestUi ui;
    8. ui.setupUi( &mw );
    9. mw.show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    testUi.h:
    Qt Code:
    1. namespace Ui {
    2.  
    3. class TestUi
    4. {
    5. public:
    6. QWidget *centralwidget;
    7. QMenuBar *menubar;
    8. QStatusBar *statusbar;
    9.  
    10. void setupUi(QMainWindow *MainWindow)
    11. {
    12. if (MainWindow->objectName().isEmpty())
    13. MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
    14. MainWindow->resize(469, 233);
    15. MainWindow->setWindowIcon(QIcon(QString::fromUtf8("images/green.png")));
    16. centralwidget = new QWidget(MainWindow);
    17. centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
    18. MainWindow->setCentralWidget(centralwidget);
    19. menubar = new QMenuBar(MainWindow);
    20. menubar->setObjectName(QString::fromUtf8("menubar"));
    21. menubar->setGeometry(QRect(0, 0, 469, 30));
    22. MainWindow->setMenuBar(menubar);
    23. statusbar = new QStatusBar(MainWindow);
    24. statusbar->setObjectName(QString::fromUtf8("statusbar"));
    25. MainWindow->setStatusBar(statusbar);
    26.  
    27. retranslateUi(MainWindow);
    28.  
    29. QMetaObject::connectSlotsByName(MainWindow);
    30. } // setupUi
    31.  
    32. void retranslateUi(QMainWindow *MainWindow)
    33. {
    34. MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
    35. Q_UNUSED(MainWindow);
    36. } // retranslateUi
    37.  
    38. };
    39.  
    40. }
    To copy to clipboard, switch view to plain text mode 

    green.png is a 32-bit png.
    Last edited by watashi16; 6th December 2007 at 16:55. Reason: updated contents

  4. #4
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    63
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Qt3 to Qt4 transition, setWindowIcon() problems

    Possible you have to write something like this
    file test.h
    Qt Code:
    1. #ifndef __test_h
    2. #define __test_h
    3.  
    4. namespace Ui {
    5. class test;
    6. };
    7.  
    8. class YourWindow : public QMainWindow
    9. {
    10. Q_OBJECT
    11. public:
    12. YourWindow (QWidget *parent=0, Qt::WFlags f=0);
    13. ...
    14. private:
    15. Ui::test *UI;
    16. ...
    17. };
    To copy to clipboard, switch view to plain text mode 
    test.cpp
    Qt Code:
    1. #include "ui_test.h"
    2.  
    3. #include "test.h"
    4.  
    5. YourWindow :: YourWindow (QWidget *parent, Qt::WFlags f) :
    6. QMainWindow (parent, f)
    7. {
    8. UI = new Ui::test;
    9. UI->setup (this);
    10. ...
    11. }
    12.  
    13. ...
    To copy to clipboard, switch view to plain text mode 
    file main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "test.h"
    3.  
    4. int main (int argc, char **argv)
    5. {
    6. QApplication app (argc, argv);
    7. YourWindow form;
    8.  
    9. form.show ();
    10. return app.exec ();
    11. }
    To copy to clipboard, switch view to plain text mode 
    Best regards,
    Yuriy Rusinov.

  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: Qt3 to Qt4 transition, setWindowIcon() problems

    You are using a relative path to the image. It might be that the application is started from a path other than you think and the image doesn't get displayed. Either make sure the path is correct (for example by changing to an absolute path or by changing the current directory to the applicationDir() before you create the widget) or use Qt resource system (see docs for details) to embed the icon within your binary.

  6. #6
    Join Date
    Dec 2007
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb Re: Qt3 to Qt4 transition, setWindowIcon() problems

    All - thanks for your help. It turns out that since Qt has started enforcing rules in the ICCCM, Hummingbird hasn't had a chance to catch up with the new specs. Because of this, Qt thinks that there's an unknown window manager sitting around, and thus defaults the icon to 1-bit depth, which causes the behavior I was seeing. Outside of modifying the Qt source, there doesn't seem to be a workaround. I'm talking to both Trolltech and Hummingbird about the problem. Thanks again!

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.