silence
12th April 2010, 06:23
Hi,
I have a class named MyIconText that derived from QWidget, and it has two QLabel in it.
class MyIconText : public QWidget
{
public:
MyIconText(const QString& text, const QPixmap& pixmap, QWidget* parent = 0)
:QWidget(parent)
{
QVBoxLayout* layout = new QVBoxLayout;
setLayout(layout);
QLabel *icon = new QLabel(this);
icon->setPixmap(pixmap);
layout->addWidget(icon);
layout->addWidget(new QLabel(text, this));
}
};
When I add MyIconText into QFrame and try to fetch it's location by childAt() when user click mouse on it.
by the childAt() function will not return the pointer of MyIconText, but it return the pointer of QLabel in MyIconText.
class MyFrame : public QFrame
{
........
void MyFrame::mousePressEvent(QMouseEvent* event)
{
QWidget* widget = childAt(event->pos());
}
}
quetions:
1) How do I let the childAt() return the pointer of MyIconText?
2) is there any better way to contain a icon and label together? because QLabel can not show icon and text at the same time.
thanks!
I have a class named MyIconText that derived from QWidget, and it has two QLabel in it.
class MyIconText : public QWidget
{
public:
MyIconText(const QString& text, const QPixmap& pixmap, QWidget* parent = 0)
:QWidget(parent)
{
QVBoxLayout* layout = new QVBoxLayout;
setLayout(layout);
QLabel *icon = new QLabel(this);
icon->setPixmap(pixmap);
layout->addWidget(icon);
layout->addWidget(new QLabel(text, this));
}
};
When I add MyIconText into QFrame and try to fetch it's location by childAt() when user click mouse on it.
by the childAt() function will not return the pointer of MyIconText, but it return the pointer of QLabel in MyIconText.
class MyFrame : public QFrame
{
........
void MyFrame::mousePressEvent(QMouseEvent* event)
{
QWidget* widget = childAt(event->pos());
}
}
quetions:
1) How do I let the childAt() return the pointer of MyIconText?
2) is there any better way to contain a icon and label together? because QLabel can not show icon and text at the same time.
thanks!