Hi,
I have a class named MyIconText that derived from QWidget, and it has two QLabel in it.
{
public:
MyIconText
(const QString
& text,
const QPixmap
& pixmap,
QWidget* parent
= 0) {
setLayout(layout);
icon->setPixmap(pixmap);
layout->addWidget(icon);
layout
->addWidget
(new QLabel(text,
this));
}
};
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));
}
};
To copy to clipboard, switch view to plain text mode
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.
{
........
{
QWidget* widget
= childAt
(event
->pos
());
}
}
class MyFrame : public QFrame
{
........
void MyFrame::mousePressEvent(QMouseEvent* event)
{
QWidget* widget = childAt(event->pos());
}
}
To copy to clipboard, switch view to plain text mode
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!
Bookmarks