Earlier the FontSelector had its own label, which in retrospect was a stupid idea.
Much better to just consider the demo widget and choose button parts of the FontSelector
widget and have settingspages supply their own description label - or checkbox.
This makes it much easier to have a font disableable, without introducing the need for
multi-property autowidgets.
#include "fontselector.h"
FontSelector::FontSelector(QWidget *parent) : QWidget(parent) {
#include "fontselector.h"
FontSelector::FontSelector(QWidget *parent) : QWidget(parent) {
- init();
-}
-
-FontSelector::FontSelector(const QString &label, QWidget *parent) : QWidget(parent) {
- init(label);
-}
-
-void FontSelector::init(const QString &label) {
QHBoxLayout *layout = new QHBoxLayout(this);
QPushButton *chooseButton = new QPushButton(tr("Choose..."), this);
connect(chooseButton, SIGNAL(clicked()), SLOT(chooseFont()));
QHBoxLayout *layout = new QHBoxLayout(this);
QPushButton *chooseButton = new QPushButton(tr("Choose..."), this);
connect(chooseButton, SIGNAL(clicked()), SLOT(chooseFont()));
- layout->addWidget(_label = new QLabel(label));
layout->addWidget(_demo = new QLabel("Font"));
layout->addWidget(chooseButton);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(_demo = new QLabel("Font"));
layout->addWidget(chooseButton);
layout->setContentsMargins(0, 0, 0, 0);
-void FontSelector::setText(const QString &label) {
- _label->setText(label);
-}
-
void FontSelector::setSelectedFont(const QFont &font) {
_font = font;
_demo->setText(QString("%1 %2pt").arg(font.family()).arg(font.pointSize()));
void FontSelector::setSelectedFont(const QFont &font) {
_font = font;
_demo->setText(QString("%1 %2pt").arg(font.family()).arg(font.pointSize()));
class FontSelector : public QWidget {
Q_OBJECT
Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
class FontSelector : public QWidget {
Q_OBJECT
Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
- Q_PROPERTY(QString text READ text WRITE setText)
public:
FontSelector(QWidget *parent = 0);
public:
FontSelector(QWidget *parent = 0);
- FontSelector(const QString &label, QWidget *parent = 0);
inline const QFont &selectedFont() const { return _font; }
inline const QFont &selectedFont() const { return _font; }
- inline QString text() const { return _label->text(); }
- void setText(const QString &label);
void setSelectedFont(const QFont &font);
signals:
void setSelectedFont(const QFont &font);
signals:
- QLabel *_demo, *_label;
-
- void init(const QString &label = "Font");
};
#endif // FONTSELECTOR_H_
};
#endif // FONTSELECTOR_H_