CustomItemDelegate
::CustomItemDelegate(QObject *parent
) :{
_state
= QStyle::State_Enabled;
}
void CustomItemDelegate
::paint(QPainter *painter,
{
QString strIcon
= widget.
iconName();
QRect rect
= option.
rect;
buttonRect.setWidth( 30);
button.icon = pq;
button.
iconSize = QSize(22,
22);
button.palette = option.palette;
button.rect = buttonRect;
//button.text = text;
button.
state = _state |
QStyle::State_Enabled;
(QStyle::CE_PushButton,
&button, painter
);
}
{
//hard coding size for test purpose,
//actual size hint can be calculated from option param
}
bool CustomItemDelegate
::editorEvent(QEvent *event,
{
m_strName = widget.name();
if( event
->type
() == QEvent::MouseButtonPress ||
event
->type
() == QEvent::MouseButtonRelease ) { } else {
//ignoring other mouse event and reseting button's state
_state
= QStyle::State_Raised;
return true;
}
QRect buttonRect
( option.
rect);
//buttonRect.setY(option.rect.y()+ 35);
//buttonRect.setHeight( 30);
buttonRect.setWidth( 30);
QMouseEvent* mouseEvent
= static_cast<QMouseEvent
*>
(event
);
if( !buttonRect.contains( mouseEvent->pos()) ) {
_state
= QStyle::State_Raised;
return true;
}
{
if(m_nOldName != widget.name() && m_nOldName != ""){
_state
= QStyle::State_Raised;
return true;
}
if( event
->type
() == QEvent::MouseButtonPress){
//if(_state == QStyle::State_Sunken)
// _state = QStyle::State_Raised;
//else
// _state = QStyle::State_Sunken;
}
else if( event
->type
() == QEvent::MouseButtonRelease) { if(_state
== QStyle::State_Sunken){ _state
= QStyle::State_Raised;
}else{
_state
= QStyle::State_Sunken;
m_nOldName = widget.name();
}
}
}
else if( event
->type
() == QEvent::MouseButtonPress) { _state
= QStyle::State_Sunken;
} else if( event
->type
() == QEvent::MouseButtonRelease) { _state
= QStyle::State_Raised;
emit buttonClicked( index);
emit pressDel(m_strName);
}
return true;
}
CustomItemDelegate::CustomItemDelegate(QObject *parent) :
QItemDelegate(parent)
{
_state = QStyle::State_Enabled;
}
void CustomItemDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
const QSortFilterProxyModel* model =
static_cast<const QSortFilterProxyModel*>(index.model());
QDesignerWidgetBoxInterface::Widget widget =((WidgetBoxCategoryModel*)model->sourceModel())->widgetAt(index);
QString strIcon = widget.iconName();
QString text = widget.name();
QRect rect = option.rect;
QRect buttonRect( rect);
buttonRect.setWidth( 30);
QStyleOptionButton button;
QIcon pq(strIcon);
button.icon = pq;
button.iconSize = QSize(22, 22);
button.palette = option.palette;
button.rect = buttonRect;
//button.text = text;
button.state = _state | QStyle::State_Enabled;
QApplication::style()->drawControl
(QStyle::CE_PushButton, &button, painter);
}
QSize CustomItemDelegate::sizeHint(const QStyleOptionViewItem &/*option*/,
const QModelIndex &/*index*/) const
{
//hard coding size for test purpose,
//actual size hint can be calculated from option param
return QSize(800,30);
}
bool CustomItemDelegate::editorEvent(QEvent *event,
QAbstractItemModel *model,
const QStyleOptionViewItem &option,
const QModelIndex &index)
{
const QSortFilterProxyModel* modelx =
static_cast<const QSortFilterProxyModel*>(index.model());
QDesignerWidgetBoxInterface::Widget widget =((WidgetBoxCategoryModel*)modelx->sourceModel())->widgetAt(index);
m_strName = widget.name();
if( event->type() == QEvent::MouseButtonPress ||
event->type() == QEvent::MouseButtonRelease ) {
} else {
//ignoring other mouse event and reseting button's state
_state = QStyle::State_Raised;
return true;
}
QRect buttonRect( option.rect);
//buttonRect.setY(option.rect.y()+ 35);
//buttonRect.setHeight( 30);
buttonRect.setWidth( 30);
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
if( !buttonRect.contains( mouseEvent->pos()) ) {
_state = QStyle::State_Raised;
return true;
}
if(widget.getFunction() == QDesignerWidgetBoxInterface::Widget::Creator)
{
if(m_nOldName != widget.name() && m_nOldName != ""){
_state = QStyle::State_Raised;
return true;
}
if( event->type() == QEvent::MouseButtonPress){
//if(_state == QStyle::State_Sunken)
// _state = QStyle::State_Raised;
//else
// _state = QStyle::State_Sunken;
}
else if( event->type() == QEvent::MouseButtonRelease) {
if(_state == QStyle::State_Sunken){
_state = QStyle::State_Raised;
}else{
_state = QStyle::State_Sunken;
m_nOldName = widget.name();
}
}
}
else if( event->type() == QEvent::MouseButtonPress) {
_state = QStyle::State_Sunken;
} else if( event->type() == QEvent::MouseButtonRelease) {
_state = QStyle::State_Raised;
emit buttonClicked( index);
emit pressDel(m_strName);
}
return true;
}
To copy to clipboard, switch view to plain text mode
Bookmarks