View Full Version : icons on image
yuvaraj.yadav
21st April 2009, 07:05
Hi
How do display icons on image, when i am moving curser on image..
please suggest me to set icons on image
Thanks
Yuvaraj R
spirit
21st April 2009, 07:28
have a look at QPainter::drawImage or QPainter::drawPixmap.
yuvaraj.yadav
21st April 2009, 07:46
Hi
Just had gone through that one...
can anybody post the sample code here
Thanks
Yuvaraj R
spirit
21st April 2009, 07:52
you should write something like this
...
QPixmap pixmap(100, 100);
QPixmap icon("incon.png");
QRectF target(10.0, 20.0, 80.0, 60.0);
QRectF source(0.0, 0.0, 70.0, 40.0);
QPainter painter(&pixmap);
painter.drawPixmap(target, icon, source);
...
yuvaraj.yadav
21st April 2009, 07:59
Don't mistake me
How do i run this code
Thanks
yuvaraj
spirit
21st April 2009, 08:05
like this
#include <QtGui>
#include <QApplication>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QPixmap pixmap("image.png");
QPixmap icon("test.png");
QPainter painter(&pixmap);
painter.drawPixmap(QPoint(10, 10), icon);
QLabel label;
label.setPixmap(pixmap);
label.show();
return app.exec();
}
yuvaraj.yadav
21st April 2009, 08:13
Hi
Thanks spirit
How can i set the icons ,it si visible only when curser is moving on image
Please suggest me
Thanks
Yuvaraj
R
spirit
21st April 2009, 08:15
use code above in mouseMove or keyPressEvent.
yuvaraj.yadav
21st April 2009, 08:23
thanks for your reply
can i set actions for label to display that
aamer4yu
21st April 2009, 08:33
Dont mistake me, but do you use Qt Assistant ? or see Qt Demos ?
As for your problem, you could use a QToolButton or QPushButton, and set the icon when mouse is over it. You will need to subclass them, and as spirit said, override the mouse events.
If you are using label, you could make button as a child of label, and show/hide when the user hovers over a given area. For this too, you will need to subclass QLabel
yuvaraj.yadav
21st April 2009, 08:57
Hi
I can we display the image using push button and tool button
aamer4yu
21st April 2009, 09:47
Read documentation for QToolButton and QPushButton
yuvaraj.yadav
21st April 2009, 10:17
Hi
Thanks for your reply..
I thing is different...
Initially i am showing one image using
this code
ui->mylabel->setPixmap(QPixmap("yuvaraj.png"));
then when i am moving the curser on image , that 4 icons will be displaying on image that time..
Here i have used the label to display my image ...But label doesn't have mouse over,click event options.
How can i do this
Don't mistake me ,i am a beginner..
Please suggest me
Thanks
Yuvaraj R
spirit
21st April 2009, 10:24
set setMouseTracking in true for a label and then process mouseMoveEvent of the label.
yuvaraj.yadav
21st April 2009, 10:42
That one problem of mine..
If click the slot options for label ,it is showng only 5 options,,,
like
1) link activated
2) link hy..
3) destroyed
4) destroyed(QObject *)
5)costumcontextmenu required...
I don't get slots like mouseover, clicked like that...
That why i am struggling.....
please suggest me
Thanks
Yuvaraj R
spirit
21st April 2009, 10:43
yes, there is no such slot like mouseOver, you have to process QMouseEvent.
yuvaraj.yadav
21st April 2009, 12:38
hi
My code for mouse over event
bool mouseover()
{
if(QPoint(10,10)
{
return TRUE; QPixmap pixmap("image.png");
QPixmap icon("test.png");
QPainter painter(&pixmap);
painter.drawPixmap(QPoint(10, 10), icon);
QLabel label;
label.setPixmap(pixmap);
label.show();
}
else
{
return FALSE;
}
}
But it is not working , i think my problem is in condition....
I have another doubt...
if mouse satisfied the position of image ,how do display the icons on image,
Is it using the push button, tool button. I need that icons should in event...
please suggest me
Thanks
Yuvaraj R
spirit
21st April 2009, 12:50
you never reach this code
...
QPixmap pixmap("image.png");
QPixmap icon("test.png");
QPainter painter(&pixmap);
painter.drawPixmap(QPoint(10, 10), icon);
QLabel label;
label.setPixmap(pixmap);
label.show();
...
because return true; is located in a wrong place
try this
bool mouseover()
{
if(QPoint(10,10)) {
QPixmap pixmap("image.png");
QPixmap icon("test.png");
QPainter painter(&pixmap);
painter.drawPixmap(QPoint(10, 10), icon);
QLabel label;
label.setPixmap(pixmap);
label.show();
return TRUE;
}
return FALSE;
}
yuvaraj.yadav
21st April 2009, 12:56
But it is giving error in main program
My main program code is
#include <QtGui/QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
the errors is
E:/Qt Programs/yuvaraj/main.cpp:10: error: expected `}' at end of input
E:/Qt Programs/yuvaraj/main.cpp:10: error: expected unqualified-id at end of input
spirit
21st April 2009, 13:08
can you attach your project?
yuvaraj.yadav
21st April 2009, 13:12
please find my project code here
i cleared my previous errors ,now i am getting new type errors..
spirit
21st April 2009, 13:17
ok, you project doen't work and will not work at all.
I'll prepare an example for you and you can learn how it should be.
spirit
21st April 2009, 13:44
have a look at this example
yuvaraj.yadav
21st April 2009, 14:04
Thank you spirit
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.