Page 1 of 2 12 LastLast
Results 1 to 20 of 34

Thread: make a .jpg or .bmp picture into a widget...?

  1. #1
    Join Date
    Jun 2008
    Posts
    23
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Question make a .jpg or .bmp picture into a widget...?

    Hi all, this is my first post here...
    I have a question, how do we load a picture file into a widget? My ultimate aim is to enable an icon to blink when there is positive integer data input... else the icon should be in disabled mode. How can I load my pictures into widgets without actually drawing it out using code?
    Also, to enable the blinking of the icon, the input data should fufill the condtion of being a positive integer. So is one of the way to do it is, create a widget with a conditional slot?

    Many Thanks in advance.

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: make a .jpg or .bmp picture into a widget...?

    I'm not entirely sure what you're going for, but from what you wrote, I think your best bet will be to subclass whatever widget you want and implement the extra functionality you need, like if you're wanting an icon to have different states than the norm.

  3. #3
    Join Date
    Jun 2008
    Posts
    23
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: make a .jpg or .bmp picture into a widget...?

    subclass widgets that I want...? hmm.. sorry i don't quite get what you mean. Can you elaborate?
    As for myself, let me explain myself clearer... apologies if I am still not clear enough as I am new to QT and sometimes I am not sure what terms are used.
    Currently I am trying to load my picture file (.jpg or .bmp) and make it into a widget. I was thinking of inheriting from the movie widget but still i am stuck with the question as to how to upload my file and make it a widget...

  4. #4
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: make a .jpg or .bmp picture into a widget...?

    Okay, if you're wanting a class to hold an image file, lookup QPixmap or QImage. If you're wanting to display an image file on screen, lookup QLabel.

  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: make a .jpg or .bmp picture into a widget...?

    For blinking an icon, u can use a QTimer.
    on the timeout event, check the current state of the icon and change the bitmap/png accordingly.

  6. #6
    Join Date
    Jun 2008
    Posts
    23
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: make a .jpg or .bmp picture into a widget...?

    Hi JimDaniel, I have looked through the QPixmap and QImage, but I have a problem though, for I have no idea how to use the functions to hold a image file. Do I use the following function?

    QPixmap ( const QString & fileName, const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor )

    Is it possible to show me a simple example of showing a picture using QPixmap?

    Hi aamer4yu,
    For blinking an icon, u can use a QTimer.
    on the timeout event, check the current state of the icon and change the bitmap/png accordingly.
    Do you mean to code in the QTimer within the code, or I am able to create a Picture Widget with a slot to connect to in the QT Designer?

    Many thanks.

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: make a .jpg or .bmp picture into a widget...?

    something like -

    Qt Code:
    1. connect(m_timer,timeout(),this, onTimer());
    2. if(input.isNegative())
    3. {
    4. ___startBlinking();
    5. }
    6.  
    7. void startBlinking()
    8. {
    9. m_timer.start();
    10. }
    11.  
    12. void onTimer()
    13. { iconNumber = (iconNumber +1) % 2;
    14. if(iconNumber)
    15. _____m_label->setIcon(icon1);
    16. else
    17. _____m_label->setIcon(icon2);
    18. }
    To copy to clipboard, switch view to plain text mode 

    hope u get the idea

  8. The following user says thank you to aamer4yu for this useful post:

    mynahz (6th June 2008)

  9. #8
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: make a .jpg or .bmp picture into a widget...?

    Quote Originally Posted by mynahz View Post
    Hi JimDaniel, I have looked through the QPixmap and QImage, but I have a problem though, for I have no idea how to use the functions to hold a image file. Do I use the following function?

    QPixmap ( const QString & fileName, const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor )

    Is it possible to show me a simple example of showing a picture using QPixmap?
    This is the constructor, and yes, as you can see, the first parameter takes in a string filename for the pixmap. See below for an example.

    Keep in mind, you can use QPixmap to store an image file, but if you want to display an image on screen, you need to use QLabel. But to show you a quick example.

    QPixmap:
    Qt Code:
    1. QPixmap pixmap("c:/my_image.jpg");
    2.  
    3. //or
    4.  
    5. QPixmap pixmap;
    6. pixmap.load("c:/my_image.jpg");
    To copy to clipboard, switch view to plain text mode 

    QLabel:
    Qt Code:
    1. QLabel label("c:/my_image.jpg");
    2.  
    3. //or
    4.  
    5. QLabel label;
    6. label.setPixmap("c:/my_image.jpg");
    7.  
    8. //or more often
    9.  
    10. QLabel * label = new QLabel("c:/my_image.jpg");
    To copy to clipboard, switch view to plain text mode 

  10. The following user says thank you to JimDaniel for this useful post:

    mynahz (6th June 2008)

  11. #9
    Join Date
    Jun 2008
    Posts
    23
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: make a .jpg or .bmp picture into a widget...?

    Hi aamer4yu,
    looking at your example, I think I get the idea already. Will work on it after i get the picture up. Thanks thanks!!

    Hi JimDaniel,
    thanks for the examples! but... I tried this and i get an empty window...

    Qt Code:
    1. /*************main.cpp****************/
    2. #include <QApplication>
    3.  
    4. #include "blinkingicon.h"
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication app(argc, argv);
    9. blinkingicon picIcon;
    10. picIcon.show();
    11. return app.exec();
    12. }
    13.  
    14. /*************BlinkingIcon.h*******************/
    15. #ifndef blinkingicon_H
    16. #define blinkingicon_H
    17.  
    18. #include <QWidget>
    19.  
    20. class blinkingicon : public QWidget
    21. {
    22. Q_OBJECT
    23.  
    24. public:
    25. blinkingicon(QWidget *parent = 0);
    26. void displayIcon();
    27. //protected:
    28. };
    29.  
    30. #endif
    31.  
    32.  
    33. /*************BlinkingIcon.cpp*****************/
    34.  
    35. #include <QtGui>
    36.  
    37. #include "blinkingicon.h"
    38.  
    39. blinkingicon::blinkingicon(QWidget *parent)
    40. : QWidget(parent)
    41. {
    42. setWindowTitle(tr("My Pic"));
    43. resize(200, 200);
    44. //Doesn't show even if I put this here...
    45. //QPixmap pixmap("C:/HmiProject/blinkingIcon/sprites/ship/ship0000.png");
    46. }
    47.  
    48. void blinkingicon::displayIcon()
    49. {
    50. QPixmap pixmap;
    51. pixmap.load("C:/HmiProject/blinkingIcon/sprites/ship/ship0000.png");
    52. }
    To copy to clipboard, switch view to plain text mode 

    Any idea what went wrong?

  12. #10
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: make a .jpg or .bmp picture into a widget...?

    Yes, there are a few problems. QPixmap has no on-screen representation. It is purely used for holding and manipulating an image file. Also, when you create a pixmap like this,

    QPixmap pixmap("c:/my_image.png");

    or

    QPixmap pixmap;
    pixmap.load("c:/my_image.png");

    It only has local scope, when the function where its declared ends, the pixmap is destroyed, which does you no good for your intention, besides the fact that a QPixmap is the wrong object to create. That is why you use (class-scope) pointers to objects created on the heap with "new". (See my example below)

    To accomplish what you want to do here, you need to use a QLabel. Something like this should get you started.

    Qt Code:
    1. #ifndef _BLINKING_ICON_
    2. #define _BLINKING_ICON_
    3.  
    4. #include <QWidget>
    5. #include <QLabel>
    6.  
    7. class BlinkingIcon : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. BlinkingIcon(QWidget * parent = 0);
    13. virtual ~BlinkingIcon();
    14.  
    15. private:
    16. QLabel * display_image;
    17. }
    18.  
    19. #endif
    20.  
    21. BlinkingIcon::BlinkingIcon(QWidget * parent) : QWidget(parent)
    22. {
    23. this->setWindowTitle(tr("My Blinking Icon"));
    24. this->resize(200, 200);
    25.  
    26. display_image = new QLabel(this);
    27. display_image->setPixmap(QPixmap("c:/my_image.png"));
    28. display_image->adjustSize();
    29. }
    30.  
    31. BlinkingIcon::~BlinkingIcon(){}
    To copy to clipboard, switch view to plain text mode 

    For your purposes, you'll probably also want to research QLayouts...
    Last edited by JimDaniel; 6th June 2008 at 06:14.

  13. The following user says thank you to JimDaniel for this useful post:

    mynahz (8th June 2008)

  14. #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: make a .jpg or .bmp picture into a widget...?

    Maybe you should also consider a simpler approach?

    For example you can use a checkbox and style it with stylesheets, like shown here:
    http://doc.trolltech.com/latest/styl...zing-qcheckbox

    You can do it with a radio button too. Just make sure those buttons are not clickable.

    Using QLabel with QMovie is also a possible solution.

  15. The following user says thank you to wysota for this useful post:

    mynahz (8th June 2008)

  16. #12
    Join Date
    Jun 2008
    Posts
    23
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: make a .jpg or .bmp picture into a widget...?

    Hi JimDaniel,
    I have tried using your example but why do I get errors like this?
    Qt Code:
    1. src\blinkingicon.cpp:4: error: new types may not be defined in a return type
    2. src\blinkingicon.cpp:4: note: (perhaps a semicolon is missing after the definition of `BlinkingIcon')
    3. src\blinkingicon.cpp:4: error: return type specification for constructor invalid
    4. src\blinkingicon.cpp:10:35: warning: unknown escape sequence '\H'
    5. mingw32-make[1]: *** [build\host\blinkingicon.o] Error 1
    6. mingw32-make: *** [release] Error 2
    To copy to clipboard, switch view to plain text mode 

    The actual code i used is exactly the same as what you have given me, only difference is just that i split it into a .h and a .cpp... like this...

    Qt Code:
    1. #ifndef __BLINKINGICON_H__
    2. #define __BLINKINGICON_H__
    3.  
    4. #include <QWidget>
    5. #include <QLabel>
    6.  
    7. class BlinkingIcon : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. BlinkingIcon(QWidget * parent = 0);
    13. virtual ~BlinkingIcon();
    14.  
    15. private:
    16. QLabel * display_image;
    17. }
    18.  
    19.  
    20. #endif // __BLINKINGICON_H__
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "blinkingicon.h"
    2.  
    3. BlinkingIcon::BlinkingIcon(QWidget * parent)
    4. : QWidget(parent)
    5. {
    6. this->setWindowTitle(tr("My Blinking Icon"));
    7. this->resize(200, 200);
    8.  
    9. display_image = new QLabel(this);
    10. display_image->setPixmap(QPixmap("C:\HmiProject\test\nyjc.bmp"));
    11. display_image->adjustSize();
    12. }
    13.  
    14. BlinkingIcon::~BlinkingIcon(){}
    To copy to clipboard, switch view to plain text mode 

    Once again, thanks for your patient help given.

    Hi wysota,
    pardon me for my ignorance, but what does it mean by "The main difference is that a tristate QCheckBox has an indeterminate state." from the website? Is the example using an existing class QCheckBox, and giving it more functions to act as an indicator? the code... does it mean that the QCheckBox named indicator has a function indeterminateressed? I am having difficultity understanding the codes... Can you explain briefly?
    Qt Code:
    1. QCheckBox::indicator:indeterminate:pressed {
    2. image: url(:/images/checkbox_indeterminate_pressed.png);
    3. }
    To copy to clipboard, switch view to plain text mode 

    Thanks!!

  17. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: make a .jpg or .bmp picture into a widget...?

    The compiler has already suggested what's wrong:
    src\blinkingicon.cpp:4: note: (perhaps a semicolon is missing after the definition of `BlinkingIcon')

  18. #14
    Join Date
    Jun 2008
    Posts
    23
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: make a .jpg or .bmp picture into a widget...?

    i actually tried putting the semicolon but the error still resides...

    and when i start another project and did the same thing, i actually get another set of errors!
    let me show u all my codes in the whole project..
    here is the main.cpp...
    Qt Code:
    1. #include <QApplication>
    2.  
    3. #include "BlinkingIcon.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8. BlinkingIcon picIcon;
    9. picIcon.show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    next is the blinkingicon.h...
    Qt Code:
    1. #ifndef __BLINKINGICON_H__
    2. #define __BLINKINGICON_H__
    3.  
    4. #include <QWidget>
    5. #include <QLabel>
    6.  
    7. class BlinkingIcon : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. BlinkingIcon(QWidget *parent = 0);
    13. virtual ~BlinkingIcon();
    14.  
    15. private:
    16. QLabel * display_image;
    17. }
    18.  
    19. #endif //__BLINKINGICON_H__
    To copy to clipboard, switch view to plain text mode 

    following which, is the blinkingicon.cpp...
    Qt Code:
    1. #include "BlinkingIcon.h"
    2.  
    3. BlinkingIcon::BlinkingIcon(QWidget * parent)
    4. : QWidget(parent)
    5. {
    6. this->setWindowTitle(tr("My Blinking Icon"));
    7. this->resize(200,200);
    8.  
    9. display_image = new QLabel(this);
    10. display_image->setPixmap(QPixmap("C:\HmiProject\blinkingIcon\sprites\ship\ship0000.png"));
    11. display_image->adjustSize();
    12. }
    13.  
    14. BlinkingIcon::~BlinkingIcon(){}
    To copy to clipboard, switch view to plain text mode 

    the new set of errors i am getting now is...
    Qt Code:
    1. src\main.cpp:7: error: new types may not be defined in a return type
    2. src\main.cpp:7: note: (perhaps a semicolon is missing after the definition of `BlinkingIcon')
    3. src\main.cpp:7: error: extraneous `int' ignored
    4. src\main.cpp: In function `BlinkingIcon qMain(int, char**)':
    5. src\main.cpp:11: error: invalid conversion from `int' to `QWidget*'
    6. src\main.cpp:11: error: initializing argument 1 of `BlinkingIcon::BlinkingIcon(QWidget*)'
    7. src\main.cpp: In copy constructor `BlinkingIcon::BlinkingIcon(const BlinkingIcon&)':
    8. ../../HMIDeveloper/Qt/include/QtGui/../../src/gui/kernel/qwidget.h:720: error: `QWidget::QWidget(const QWidget&)' is private
    9. src\main.cpp:11: error: within this context
    10. src\main.cpp: In function `BlinkingIcon qMain(int, char**)':
    11. src\main.cpp:11: error: initializing temporary from result of `BlinkingIcon::BlinkingIcon(QWidget*)'
    12. mingw32-make[1]: *** [build\host\main.o] Error 1
    13. mingw32-make: *** [release] Error 2
    To copy to clipboard, switch view to plain text mode 

    I don't quite get it... line 7 of main.cpp is a "{", no BlinkingIcon definition until line 9... as for line 11 i tried changing the return type to "int" type by "int(app.exec() )" but it also doesn't work. another thing i tried was to put "QWidget main(int argc, char *argv[])" or "void main(int argc, char *argv[])" instead of "int main(int argc, char *argv[])" but it doesn't help either.
    As for the other errors at line 11 (regarding qMain), I am totally lost.
    Hope you guys can enlighten me... Thanks loads!!!

  19. #15
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: make a .jpg or .bmp picture into a widget...?

    Try putting a semi-colon after the BlinkingIcon class defintion, in your header file. I was getting compile errors with the code until I did that. Now it works fine.

  20. #16
    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: make a .jpg or .bmp picture into a widget...?

    Quote Originally Posted by mynahz View Post
    pardon me for my ignorance, but what does it mean by "The main difference is that a tristate QCheckBox has an indeterminate state." from the website?
    It means the checkbox can be checked, unchecked or "partially checked".

  21. The following user says thank you to wysota for this useful post:

    mynahz (9th June 2008)

  22. #17
    Join Date
    Jun 2008
    Posts
    23
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: make a .jpg or .bmp picture into a widget...?

    Try putting a semi-colon after the BlinkingIcon class defintion, in your header file. I was getting compile errors with the code until I did that. Now it works fine.
    Hi JimDaniel,
    Do you mind posting your code here for me to compare? because I did what you did too, but I am still stuck. I show you orig. and edited (add semicolon after BlinkingIcon) here and their error messages...
    Qt Code:
    1. #ifndef __BLINKINGICON_H__
    2. #define __BLINKINGICON_H__
    3.  
    4. #include <QWidget>
    5. #include <QLabel>
    6.  
    7. class BlinkingIcon : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. BlinkingIcon(QWidget *parent = 0);
    13. virtual ~BlinkingIcon();
    14.  
    15. private:
    16. QLabel * display_image;
    17. }
    18.  
    19. #endif //__BLINKINGICON_H__
    To copy to clipboard, switch view to plain text mode 

    for this, error messages are as follows:
    src\main.cpp:7: error: new types may not be defined in a return type
    src\main.cpp:7: note: (perhaps a semicolon is missing after the definition of `BlinkingIcon')
    src\main.cpp:7: error: extraneous `int' ignored
    src\main.cpp: In function `BlinkingIcon qMain(int, char**)':
    src\main.cpp:11: error: invalid conversion from `int' to `QWidget*'
    src\main.cpp:11: error: initializing argument 1 of `BlinkingIcon::BlinkingIcon(QWidget*)'
    src\main.cpp: In copy constructor `BlinkingIcon::BlinkingIcon(const BlinkingIcon&)':
    ../../HMIDeveloper/Qt/include/QtGui/../../src/gui/kernel/qwidget.h:720: error: `QWidget::QWidget(const QWidget&)' is private
    src\main.cpp:11: error: within this context
    src\main.cpp: In function `BlinkingIcon qMain(int, char**)':
    src\main.cpp:11: error: initializing temporary from result of `BlinkingIcon::BlinkingIcon(QWidget*)'
    mingw32-make[1]: *** [build\host\main.o] Error 1
    mingw32-make: *** [release] Error 2

    for the edited version,
    Qt Code:
    1. #ifndef __BLINKINGICON_H__
    2. #define __BLINKINGICON_H__
    3.  
    4. #include <QWidget>
    5. #include <QLabel>
    6.  
    7. class BlinkingIcon :: public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. BlinkingIcon(QWidget *parent = 0);
    13. virtual ~BlinkingIcon();
    14.  
    15. private:
    16. QLabel * display_image;
    17. }
    18.  
    19. #endif //__BLINKINGICON_H__
    To copy to clipboard, switch view to plain text mode 

    and the error messages are...
    src\BlinkingIcon.h:7: error: expected identifier before "public"
    src\BlinkingIcon.h:7: error: expected unqualified-id before "public"
    src\main.cpp: In function `int qMain(int, char**)':
    src\main.cpp:9: error: `BlinkingIcon' was not declared in this scope
    src\main.cpp:9: error: expected `;' before "picIcon"
    src\main.cpp:10: error: `picIcon' was not declared in this scope
    src\main.cpp:9: warning: unused variable 'BlinkingIcon'
    src\main.cpp:10: warning: unused variable 'picIcon'
    mingw32-make[1]: Leaving directory `C:/HmiProject/blinkingIcon'
    mingw32-make[1]: *** [build\host\main.o] Error 1
    mingw32-make: *** [release] Error 2

  23. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: make a .jpg or .bmp picture into a widget...?

    Quote Originally Posted by mynahz View Post
    Do you mind posting your code here for me to compare? because I did what you did too, but I am still stuck.
    ":" is called colon, a semicolon is ";" and you are supposed to put it in line #17 of that code snippet.
    Last edited by jacek; 9th June 2008 at 19:57. Reason: typo

  24. The following user says thank you to jacek for this useful post:

    mynahz (10th June 2008)

  25. #19
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: make a .jpg or .bmp picture into a widget...?

    Qt Code:
    1. #ifndef __BLINKINGICON_H__
    2. #define __BLINKINGICON_H__
    3.  
    4. #include <QWidget>
    5. #include <QLabel>
    6.  
    7. class BlinkingIcon : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. BlinkingIcon(QWidget *parent = 0);
    13. virtual ~BlinkingIcon();
    14.  
    15. private:
    16. QLabel * display_image;
    17. };
    18.  
    19. #endif //__BLINKINGICON_H__
    To copy to clipboard, switch view to plain text mode 

  26. The following user says thank you to JimDaniel for this useful post:

    mynahz (10th June 2008)

  27. #20
    Join Date
    Jun 2008
    Posts
    23
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: make a .jpg or .bmp picture into a widget...?

    gosh, silly me! i mixed up colon and semicolon! thanks a lot to all of you!

    Qt Code:
    1. /***********blinkingicon.h***************/
    2. #ifndef __BLINKINGICON_H__
    3. #define __BLINKINGICON_H__
    4.  
    5. #include <QWidget>
    6. #include <QLabel>
    7.  
    8. class BlinkingIcon : public QWidget
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. BlinkingIcon(QWidget *parent = 0);
    14.  
    15. virtual ~BlinkingIcon();
    16.  
    17. private:
    18. QLabel * display_image1;
    19. QLabel * display_image2;
    20. QTimer * m_timer;
    21. void startBlinking();
    22. };
    23.  
    24. #endif //__BLINKINGICON_H__
    25.  
    26. /***********blinkingicon.cpp**************/
    27.  
    28. #include "BlinkingIcon.h"
    29.  
    30. BlinkingIcon::BlinkingIcon(QWidget * parent)
    31. : QWidget(parent)
    32. {
    33. setWindowTitle(tr("My Blinking Icon"));
    34. resize(200,200);
    35.  
    36. display_image1 = new QLabel(this);
    37. display_image1->setPixmap(QPixmap("C:/HmiProject/blinkingIcon/sprites/ship/ship0030.png"));
    38. display_image1->adjustSize();
    39.  
    40. display_image1->maximumSize(); //this widget maxsize is referring to picture or window max size?
    41. }
    42.  
    43. BlinkingIcon::~BlinkingIcon(){}
    To copy to clipboard, switch view to plain text mode 

    just want to find out, how do i make the picture's size to fit into the window size perfectly? I tried using maximum size(as shown) but the picture still remains at the left corner of the window...

    and another question, i tried to make the picture blink using QTimer like what aamer4yu suggested (with some changes) but i am having some errors that i can't understand...

    blinkingicon.cpp
    Qt Code:
    1. #include "BlinkingIcon.h"
    2.  
    3. BlinkingIcon::BlinkingIcon(QWidget * parent)
    4. : QWidget(parent)
    5. {
    6. setWindowTitle(tr("My Blinking Icon"));
    7. resize(200,200);
    8. /**********************************************/
    9. QTimer *timer = new QTimer(this);
    10. connect(timer, SIGNAL(timeout()), this, SLOT(startBlinking()));
    11. timer->start(1000);
    12. startBlinking();
    13. /**********************************************/
    14.  
    15. }
    16.  
    17. void BlinkingIcon::startBlinking()
    18. {
    19. QTime time = QTime::currentTime();
    20. if ((time.second() % 2) == 0)
    21. {
    22. display_image1 = new QLabel(this);
    23. display_image1->setPixmap(QPixmap("C:/HmiProject/blinkingIcon/sprites/ship/ship0030.png"));
    24. display_image1->adjustSize();
    25. display_image2->clear();
    26. }
    27. else
    28. {
    29. display_image2 = new QLabel(this);
    30. display_image2->setPixmap(QPixmap("C:/HmiProject/blinkingIcon/sprites/ship/ship0000.png"));
    31. display_image2->adjustSize();
    32. display_image1->clear();
    33. }
    34. }
    35.  
    36. BlinkingIcon::~BlinkingIcon(){}
    To copy to clipboard, switch view to plain text mode 

    here are the errors...
    ///////ERROR/////////////////////
    src\BlinkingIcon.cpp: In constructor `BlinkingIcon::BlinkingIcon(QWidget*)':
    src\BlinkingIcon.cpp:10: error: invalid use of undefined type `struct QTimer'
    ../../HMIDeveloper/Qt/include/QtGui/../../src/gui/kernel/qwindowdefs.h:78: error: forward declaration of `struct QTimer'
    src\BlinkingIcon.cpp:11: error: no matching function for call to `BlinkingIcon::connect(QTimer*&, const char[11], BlinkingIcon* const, const char[17])'
    ../../HMIDeveloper/Qt/include/QtCore/../../src/corelib/kernel/qobject.h:191: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
    ../../HMIDeveloper/Qt/include/QtCore/../../src/corelib/kernel/qobject.h:293: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
    src\BlinkingIcon.cpp:12: error: invalid use of undefined type `struct QTimer'
    ../../HMIDeveloper/Qt/include/QtGui/../../src/gui/kernel/qwindowdefs.h:78: error: forward declaration of `struct QTimer'
    src\BlinkingIcon.cpp: In member function `void BlinkingIcon::startBlinking()':
    src\BlinkingIcon.cpp:20: error: variable `QTime time' has initializer but incomplete type
    src\BlinkingIcon.cpp:20: error: incomplete type `QTime' used in nested name specifier
    mingw32-make[1]: Leaving directory `C:/HmiProject/blinkingIcon'
    mingw32-make[1]: *** [build\host\BlinkingIcon.o] Error 1
    mingw32-make: *** [release] Error 2

    This method works well for blinking of the colon in a digital clock... hope you guys can help me out...

Similar Threads

  1. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05: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.