PDA

View Full Version : Painting Faded away when alt key pressed,



rajeshs
4th July 2007, 06:39
Hi Friends,

I am using Qt 4.2 in Windows,

I am using ItemDelegate for ListWidget item , within that I am painting text and images as items using painter , If i press alt key or if i drag the mouse with in that listwiget,then all the list items are fading away,
How can i prevent this?

If anybody knows Please help me.

Thanks,
Rajesh.S

jpn
4th July 2007, 07:44
Is it a QItemDelegate subclass? Could we see the code of paint()?

rajeshs
4th July 2007, 09:45
Yes, this is subclass of QItemDelegate , Like this i am using 4 delegates for 4 seperate listwidgets in my program, and i am setting the corresponing delegates to corresponding widgets in QMainWindow subclass,


#include <QtGui>
#include "DelegateForStationsList.h"
#include<QRect>
#include<QIcon>
#include<QPixmap>

INT32 QDelegateForStationsList::x=0;
INT32 QDelegateForStationsList::y=-25;

//////////////////////////////////////////////////////////////////////////////////////
// Function : QDelegateForStationsList Constructor
//
// Parameters : *parent
// IN Parameters:None
// OUT Parameters:None
//
// Description : For initialization Purpose
//
//
// Return : void
// 0 in case of success
// -1 in case of failure
///////////////////////////////////////////////////////////////////////////////////////

QDelegateForStationsList::QDelegateForStationsList (QObject *parent)
: QItemDelegate(parent)
{

}

//////////////////////////////////////////////////////////////////////////////////////
// Function : paint
//
// Parameters : *painter,option,index
// IN Parameters:None
// OUT Parameters:None
//
// Description : paints the elements into the listwidget in customized format
//
//
// Return : void
// 0 in case of success
// -1 in case of failure
///////////////////////////////////////////////////////////////////////////////////////

void QDelegateForStationsList::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
painter->save();
painter->restore();
QString text = index.data(Qt::DisplayRole).toString();
QIcon icon1 = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
QPixmap pixmap1 = icon1.pixmap(option.decorationSize);
QIcon icon2 = qvariant_cast<QIcon>(index.data(Qt::UserRole));
QPixmap pixmap2 = icon2.pixmap(option.decorationSize);

drawDecoration(painter, option, QRect(x-5,y+17,30,30), pixmap1);
QFont textFont;
textFont.setFamily("Arial");
textFont.setPixelSize(13);
if((text=="Bad Breisig Hp")||(text=="Sinzig(Rhein)")||(text=="Remagen")||(text=="Oberwinter")||(text=="Bn-Bad Godesberg"))
textFont.setBold(true);
else
textFont.setBold(false);

painter->setFont(textFont);
painter->drawText(x+30,y+35,text);

if((text=="Sbk 23")||(text=="Sbk 367"))
{
painter->drawLine(280,y+17,273,y+24);
painter->drawLine(273,y+24,280,y+31);
painter->drawLine(280,y+31,273,y+38);
painter->drawLine(273,y+38,280,y+45);

}
y=y+25;

}
//////////////////////////////////////////////////////////////////////////////////////
// Function : reset
//
// Parameters : void
// IN Parameters:None
// OUT Parameters:None
//
// Description : resets the position for painting
//
//
// Return : void
// 0 in case of success
// -1 in case of failure
///////////////////////////////////////////////////////////////////////////////////////

void QDelegateForStationsList::reset()
{
QDelegateForStationsList::x=0;
QDelegateForStationsList::y=-25;
}