Russian Qt Forum
Октябрь 03, 2024, 05:39 *
Добро пожаловать, Гость. Пожалуйста, войдите или зарегистрируйтесь.
Вам не пришло письмо с кодом активации?

Войти
 
  Начало   Форум  WIKI (Вики)FAQ Помощь Поиск Войти Регистрация  

Страниц: [1]   Вниз
  Печать  
Автор Тема: Цвет шрифта.  (Прочитано 4500 раз)
ZIkos
Гость
« : Июль 09, 2007, 18:44 »

Как поменять в QListViewItem цвет шрифта текста в определенной колонке? Версия 3.3.1.
В 4.2.0 setForeground(color,column).
Записан
Racheengel
Джедай : наставник для всех
*******
Offline Offline

Сообщений: 2679


Я работал с дискетам 5.25 :(


Просмотр профиля
« Ответ #1 : Июль 09, 2007, 21:57 »

переопределить paint() (по моему так метод называется).
Записан

What is the 11 in the C++11? It’s the number of feet they glued to C++ trying to obtain a better octopus.

COVID не волк, в лес не уйдёт
pastor
Administrator
Джедай : наставник для всех
*****
Offline Offline

Сообщений: 2901



Просмотр профиля WWW
« Ответ #2 : Июль 09, 2007, 22:25 »

Попробуй так:

Код:

void Item::paintCell ( QPainter * p, const QColorGroup & cg, int column,
                               int width, int align )
{
    if(column == 0)
    {
        QPen oldPen(p->pen());
        QPen newPen(p->pen());
        newPen.setColor(red);
        p->setPen(newPen);
        QListViewItem::paintCell(p, cg, column, width, align);
        p->setPen(oldPen);
        return;
    }
    QListViewItem::paintCell(p, cg, column, width, align);
}


ЗЫ: В чёмто мог ошибиться, писал по памяти

добавлено спустя 3 минуты:

 Или можно так:
Код:

void Item::paintCell ( QPainter * p, const QColorGroup & cg, int column,
                               int width, int align )
{
    QPen newPen(p->pen());
    if(column == 0)  
        newPen.setColor(red);
    else
        newPen.setColor(black);    
    p->setPen(newPen);  
    QListViewItem::paintCell(p, cg, column, width, align);
}
Записан

Integrated Computer Solutions, Inc. (ICS)
http://www.ics.com/
Racheengel
Джедай : наставник для всех
*******
Offline Offline

Сообщений: 2679


Я работал с дискетам 5.25 :(


Просмотр профиля
« Ответ #3 : Июль 10, 2007, 00:05 »

Вообще делали подобное в проекте http://www.ii-system.com/soft/insense/insense.htm. Там есть сырцы открытые в архиве. Файл devicemanager_gui.cpp.

У нас выглядело примерно так:

Код:

void DeviceItem::paintCell ( QPainter * p, const QColorGroup & cg, int column, int width, int align )
{
QColorGroup cg2(cg);
if (!(m_device->isActive()))
cg2.setColor(QColorGroup::Text, Qt::gray);

// mark if there are critical issues
if (!(m_device->issues().isEmpty())) {
const DevIssueEntry& last_issue = m_device->issues().last();
if (last_issue.severity == DS_CRITICAL) {
cg2.setColor(QColorGroup::Text, Qt::red);
cg2.setColor(QColorGroup::Highlight, Qt::red);
}
}

if (column) {
QFont font(p->font());
font.setItalic(true);
p->setFont(font);
}

QListViewItem::paintCell(p, cg2, column, width, align);
}
Записан

What is the 11 in the C++11? It’s the number of feet they glued to C++ trying to obtain a better octopus.

COVID не волк, в лес не уйдёт
pastor
Administrator
Джедай : наставник для всех
*****
Offline Offline

Сообщений: 2901



Просмотр профиля WWW
« Ответ #4 : Июль 10, 2007, 09:44 »

Решение предложенное Racheengel будет правильнее моего


Код:
void Item::paintCell( QPainter *p, const QColorGroup &cg,
int column, int width, int alignment )
{
    QColorGroup _cg( cg );
    QColor c = _cg.text();

    if ( column == 0 )
_cg.setColor( QColorGroup::Text, Qt::red );

    QListViewItem::paintCell( p, _cg, column, width, alignment );

    _cg.setColor( QColorGroup::Text, c );
}
Записан

Integrated Computer Solutions, Inc. (ICS)
http://www.ics.com/
ZIkos
Гость
« Ответ #5 : Июль 10, 2007, 22:19 »

Всем спасибо. Разобрался.
Записан
Страниц: [1]   Вверх
  Печать  
 
Перейти в:  


Страница сгенерирована за 0.16 секунд. Запросов: 22.