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?
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?
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 09:15.
You can also use style sheet.
with the qProperty-iconSize target
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();
}
I wonder which way is the most convinience ways for my program. Thank you.
I would recommend using layouts instead of positioning your items by hand. For the icon just useQt Code:
To copy to clipboard, switch view to plain text mode
shihao (14th March 2010)
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
Consider using a QToolButton instead:
Qt Code:
mybutton->setIcon(myIcon); mybutton->setText("Sample text"); 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 07:43.
shihao (15th March 2010)
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
QToolButton::setMenu() and a good start is the documentation which is really good. If you have found QToolButton just read through its functions.
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.
Bookmarks