Понедельник, 23.06.2025, 18:35
Приветствую Вас Гость

QtNix

Меню сайта
Категории каталога
Qt [2]
Общие статьи по Qt
Qt (Linux) [0]
Реализации программ на Qt под Linux
Qt (Windows) [3]
Win кодинг :)
PyQt [1]
Спец фор ir4y
Мини-чат
Главная » Файлы » Программирование » Qt

QHintLineEdit
[ Скачать с сервера (0.9 Kb) ] 06.02.2009, 09:27
// QHintLineEdit.h
#ifndef QHINTLINEEDIT_H

#define QHINTLINEEDIT_H

#include <QLineEdit>

#include <QPaintEvent>

#include <QPainter>

#include <QColor>

class QHintLineEdit : public QLineEdit

{

Q_OBJECT


public:

QHintLineEdit (QWidget *parent = 0);

void setTextHint (QString text);

void setColorHint (QColor color);

void setAlignmentHint (Qt::Alignment flag);


private:

QString hintText;

Qt::Alignment hintAlignment;

QColor hintColor;

void paintEvent(QPaintEvent *event);

};

#endif // QHINTLINEEDIT_H


//QHintLineEdit.cpp

#include "QHintLineEdit.h"

QHintLineEdit::QHintLineEdit(QWidget *parent)

: QLineEdit(parent)

{

this->setAlignment(Qt::AlignCenter);

this->setAlignmentHint(Qt::AlignCenter);

this->setColorHint(Qt::lightGray);

this->setTextHint(NULL);

}

void QHintLineEdit::paintEvent(QPaintEvent *event)

{

if (text().isEmpty() && !hintText.isEmpty() && !hasFocus()){

QLineEdit::paintEvent(event);

QPainter painter(this);

QRect textRec = rect();

textRec.setLeft(textRec.left()+5);

painter.setPen(hintColor);

painter.drawText(textRec, hintAlignment, hintText);

} else QLineEdit::paintEvent(event);

}

void QHintLineEdit::setTextHint(QString text)

{

hintText = text;

}

void QHintLineEdit::setAlignmentHint(Qt::Alignment flag)

{

hintAlignment = flag;

}

void QHintLineEdit::setColorHint(QColor color)

{

hintColor = color;

}


Категория: Qt | Добавил: entmobile
Просмотров: 596 | Загрузок: 149 | Рейтинг: 0.0/0 |
Всего комментариев: 0
Имя *:
Email *:
Код *:
Форма входа
Поиск
Друзья сайта
Статистика

Онлайн всего: 1
Гостей: 1
Пользователей: 0