but is it possible for me to implement Led to label itself
Yes, you would have to modify the LED API to give you a label getter/setter, some good size hinting, and the paintEvent() to render the text in the relevant location with respect to the LED graphic. It would be easier to leave the LED code alone and create your own composite widget class with a layout containing a label and LED. The composite class should expose a way to set the label text, perhaps through the constructor, and LED colour/state. This is very basic C++ and Qt.
i tried to qlabel with absolute positioning and led with grid layout but the absolute positioning does not seem to work as it always positions at a fixed position even if i change the position using setGeometry().
The point of layouts is that you do not worry about positioning... that's the job of the layout using the constraints and content you give it.
Something like this (untested):
Q_OBJECT
public:
m_LED = new LED(this);
layout->addWidget(m_led);
layout->addWidget(m_label);
// tweak layout constraints as required
setLayout(layout);
}
void setText
(const QString &text
) { m_label
->setText
(text
);
} void setLEDColour(...) { }
void setLEDState(...) { }
private:
LED *m_led;
};
class MyLED: public QWidget {
Q_OBJECT
public:
MyLED(QWidget *p = 0): QWidget(p) {
m_LED = new LED(this);
m_label = new QLabel(this);
VBoxLayout *layout = new QVBoxLayout;
layout->addWidget(m_led);
layout->addWidget(m_label);
// tweak layout constraints as required
setLayout(layout);
}
void setText(const QString &text) { m_label->setText(text); }
void setLEDColour(...) { }
void setLEDState(...) { }
private:
LED *m_led;
QLabel *m_label;
};
To copy to clipboard, switch view to plain text mode
Bookmarks