Results 1 to 12 of 12

Thread: Qicon

  1. #1
    Join Date
    Mar 2010
    Posts
    25
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Qicon

    Hi guys,

    I am new to QT creater. What I try to do is, try to
    create a button which contains picture.

    QPushButton *hello=new QPushButto('button',this);
    hello->setIcon(QIcon(/location/pic/));

    What should I do to change the size of the icon?

  2. #2
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qicon

    Create a pixmap at the relevant size and then use the constructor:
    QIcon::QIcon ( const QPixmap & pixmap )
    Last edited by toutarrive; 14th March 2010 at 10:15.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

  4. #4
    Join Date
    Mar 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qicon

    You can also use style sheet.
    with the qProperty-iconSize target

  5. #5
    Join Date
    Mar 2010
    Posts
    25
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qicon

    Guys, Thanks for helping. I am totally new on this, can u guys be more specific.?Thank you. My program is almost like this:

    class MyWidget : public QWidget
    {
    public:
    MyWidget(QWidget *parent = 0);
    };

    MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
    {
    setFixedSize(900, 400);
    QPushButton *hello6 = new QPushButton(tr("hello6"), this);
    hello6->setGeometry(460, 200, 75, 50);
    hello6->setIcon(QIcon("/shihao/shihao2/exit.JPG"));
    }


    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    MyWidget widget;
    widget.show();
    return app.exec();
    }

  6. #6
    Join Date
    Mar 2010
    Posts
    25
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qicon

    I wonder which way is the most convinience ways for my program. Thank you.

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Qicon

    I would recommend using layouts instead of positioning your items by hand. For the icon just use
    Qt Code:
    1. hello6->setIconSize(QSize(64,64));
    To copy to clipboard, switch view to plain text mode 

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

    shihao (14th March 2010)

  9. #8
    Join Date
    Mar 2010
    Posts
    25
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qicon

    Guys, my code generate the following output:
    button with hello6

    How to generate the output which is

    Hello6

    which is hello6 word at the bottom of the qicon?

    Thanks and Regards
    Shi Hao

  10. #9
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qicon

    Consider using a QToolButton instead:
    Qt Code:
    1. QToolButton*mybutton = new QToolButton(this);
    2. mybutton->setIcon(myIcon);
    3. mybutton->setText("Sample text");
    4. mybutton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    To copy to clipboard, switch view to plain text mode 

    If it's not an option you can customize your pushButton using style sheet.
    http://doc.trolltech.com/4.2/stylesh...-the-box-model
    Last edited by toutarrive; 15th March 2010 at 08:43.

  11. The following user says thank you to toutarrive for this useful post:

    shihao (15th March 2010)

  12. #10
    Join Date
    Mar 2010
    Posts
    25
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qicon

    Guys, this forum are helpful compare to the others. Thank you very much to hose who participate.
    Anyway, Now I try to do an event, when you click on the menu, it will pop up another sub menu. Anybody know how to do it?

    However, I feel embrace to ask every single steps, anyone know any links which is sufficient for beginner?
    I have some links as well, like:
    http://doc.trolltech.com/4.3/tutorial.html
    http://digg.com/programming/Free_e_b...4_Zip_with_PDF

  13. #11
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Qicon

    QToolButton::setMenu() and a good start is the documentation which is really good. If you have found QToolButton just read through its functions.

  14. #12
    Join Date
    Mar 2010
    Posts
    25
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qicon

    hi Guys, my code is something like this,

    #include <QApplication>
    #include <QFont>
    #include <QPushButton>
    #include <QVBoxLayout>
    #include <QWidget>
    #include <QIcon>
    #include <qpixmap.h>
    #include <QAbstractButton>
    #include <QToolButton>
    #include <QStyle>
    #include <Qt>

    class MyWidget : public QWidget
    {
    public:
    MyWidget(QWidget *parent = 0);
    };

    MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
    {
    setFixedSize(900, 400);

    QToolButton * mybutton = new QToolButton(this);
    mybutton->setIcon(QIcon("/shihao/icon/icon/Technorati.JPG"));
    mybutton->setText("Sample text");
    mybutton->setToolButtonStyle(Qt::ToolButtonIconOnly);
    mybutton->setIconSize(QSize(50,70));
    mybutton->setGeometry(270, 70, 95, 100);

    QToolButton * mybutton1 = new QToolButton(this);
    mybutton1->setIcon(QIcon("/shihao/qicon/qicon7.JPG"));
    mybutton1->setText("Sample text");
    mybutton1->setToolButtonStyle(Qt::ToolButtonTextUnderIcon) ;
    mybutton1->setIconSize(QSize(50,70));
    mybutton1->setGeometry(380, 70, 95, 100);
    }

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    MyWidget widget;
    widget.show();
    return app.exec();
    }


    Apparently, the icon of first image without the text can be align properly. On the other hand, the second image looks a bit bigger in the bottom-padding. (Not same with it's top padding)
    What can I do to align the second images exactly on the center?

    Thanks in advance.
    Attached Images Attached Images

Similar Threads

  1. QIcon resize question
    By MarkoSan in forum Qt Programming
    Replies: 0
    Last Post: 22nd November 2009, 22:35
  2. Change QIcon
    By Diph in forum Qt Programming
    Replies: 2
    Last Post: 2nd August 2009, 08:29
  3. How to get the QIcon fileneme in use.
    By gt.beta2 in forum Newbie
    Replies: 1
    Last Post: 25th February 2009, 16:30
  4. QIcon Directory Location
    By QbelcorT in forum Qt Tools
    Replies: 4
    Last Post: 28th January 2009, 02:06
  5. Replies: 2
    Last Post: 31st May 2006, 22:52

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.