hi jpn,
today i m finally done with the border highlighting part. Thanks a lot for help.
But there is one more thing that is happening. i want that only the border is highlighted and not the background turns blue. i used the paint function and overrided it in my class's .cpp file. now one problem occurs.
the paint function paints the table created to white and not the color i selected. also it suppresses the effect of the drawFocus function and no focus is seen in the table.
i tried using palette in the table but can't make it work.
can u suggest somethng in that.
my code is as follows.
//griddelegate.h
{
public:
const QRect &rect
) const;
};
//griddelegate.h
class GridDelegate : public QItemDelegate
{
public:
GridDelegate(QObject *parent = 0);
void drawFocus(QPainter* painter,
const QStyleOptionViewItem &option,
const QRect &rect) const;
void paint(QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index ) const;
};
To copy to clipboard, switch view to plain text mode
//griddelegate.cpp
#include <QtGui>
#include <GridDelegate.h>
{
}
void GridDelegate
::paint(QPainter * painter,
{
if (option.
state & QStyle::State_Selected) {
painter->setBrush(brsh);
}
else if (option.
state & QStyle::State_HasFocus) {
painter->setBrush(brsh1);
}
}
void GridDelegate
::drawFocus(QPainter* painter,
{
if (option.
state & QStyle::State_HasFocus)
{
pen.setWidth(3);
painter->setPen(pen);
painter->drawRect(rect);
} else
if (option.
state & QStyle::State_Active)
{
pen.setWidth(5);
painter->setPen(pen);
painter->drawRect(rect);
} else
if (option.
state & QStyle::State_KeyboardFocusChange)
{
pen.setWidth(5);
painter->setPen(pen);
painter->drawRect(rect);
}
}
//griddelegate.cpp
#include <QtGui>
#include <GridDelegate.h>
GridDelegate::GridDelegate(QObject *parent) : QItemDelegate(parent)
{
}
void GridDelegate::paint(QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index ) const
{
if (option.state & QStyle::State_Selected)
{
QBrush brsh(Qt::red);
painter->setBrush(brsh);
}
else if (option.state & QStyle::State_HasFocus)
{
QBrush brsh1(Qt::red);
painter->setBrush(brsh1);
}
}
void GridDelegate::drawFocus(QPainter* painter,
const QStyleOptionViewItem &option,
const QRect &rect) const
{
if (option.state & QStyle::State_HasFocus)
{
QPen pen(Qt::black);
pen.setWidth(3);
painter->setPen(pen);
painter->drawRect(rect);
} else
if (option.state & QStyle::State_Active)
{
QPen pen(Qt::green);
pen.setWidth(5);
painter->setPen(pen);
painter->drawRect(rect);
} else
if (option.state & QStyle::State_KeyboardFocusChange)
{
QPen pen(Qt::black);
pen.setWidth(5);
painter->setPen(pen);
painter->drawRect(rect);
}
}
To copy to clipboard, switch view to plain text mode
in the constructor of my main program, i merely call the setItemDelegate function as suggested by u.
Bookmarks