PDA

View Full Version : QSqlRelationalDelegate Draw a clickable QToolButton



patrik08
26th February 2007, 21:44
How i can draw a rect 22x22 to make clickabel && emit a signal to parent QWidget
like a ....

QPixmap pix(22, 22);
pix.fill(normalcolor); ... ?


I tested to put in direct a QToolButton but loop to infinite..... and is a setIndexWidget....






void BaseDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
/////////qDebug() << "### index-column " << index.column();

if (index.column() == 0) {
/* not on edit only flags |= Qt::ItemIsSelectable; */
QString numer = index.model()->data(index, Qt::DisplayRole).toString();
QString text = QString("(%1)").arg(numer);
QToolButton * button1 = new QToolButton(tas);
button1->setText(text);
tas->setIndexWidget(index,button1);
} else if (index.column() == 1) {
/* not on edit only flags |= Qt::ItemIsSelectable; */
QString coder = index.model()->data(index, Qt::DisplayRole).toString();
QStyleOptionViewItem myOption = option;
myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
myOption.palette.setColor( QPalette::Text , Qt::red );
drawDisplay(painter, myOption, myOption.rect,coder);
drawFocus(painter, myOption, myOption.rect);

}
...............


}

/* header */

class BaseDelegate : public QSqlRelationalDelegate
{
Q_OBJECT

public:
BaseDelegate( QTableView *ta , QObject *parent );
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
private slots:
private:
QTableView *tas;

};

wysota
1st March 2007, 13:46
Your code doesn't make sense. Why do you create a tool button in every repaint of the cell? If you want to draw a tool button, then use QStyle::drawComplexControl() with CC_ToolButton as its parameter.

What are you trying to do exactly?

patrik08
1st March 2007, 18:41
Your code doesn't make sense. Why do you create a tool button in every repaint of the cell? If you want to draw a tool button, then use QStyle::drawComplexControl() with CC_ToolButton as its parameter.

What are you trying to do exactly?

i have 11 cell on my table only 9 ist editable from model .... and one cell wo is not editable.. i must make a link (connect) to to edit moore field in a form.... and a symple doupleclick is not inaf ..... or i draw a button inside or a qpixmap buttonstyle to append event ... wo people understand to click ,,, && open other dialog.....

I search drawComplexControl i found only a small piece code.... on

http://www.koders.com/cpp/fidE11AA04A8D74F59EABF9F7872CD7475CE51299A3.aspx?s =drawComplexControl

How i can integrate to my model .....?
is this a pain event from QSqlRelationalDelegate subclass?







void QTitleBar::paintEvent(QPaintEvent *)
{
QStyle::SCFlags ctrls = QStyle::SC_TitleBarLabel;
if ( testWFlags( WStyle_SysMenu) ) {
if ( testWFlags( WStyle_Tool ) ) {
ctrls |= QStyle::SC_TitleBarCloseButton;
if ( d->window && testWFlags( WStyle_MinMax ) ) {
if ( d->window->isMinimized() )
ctrls |= QStyle::SC_TitleBarUnshadeButton;
else
ctrls |= QStyle::SC_TitleBarShadeButton;
}
} else {
ctrls |= QStyle::SC_TitleBarSysMenu | QStyle::SC_TitleBarCloseButton;
if ( d->window && testWFlags( WStyle_Minimize ) ) {
if( d->window && d->window->isMinimized() )
ctrls |= QStyle::SC_TitleBarNormalButton;
else
ctrls |= QStyle::SC_TitleBarMinButton;
}
if ( d->window && testWFlags( WStyle_Maximize ) && !d->window->isMaximized() )
ctrls |= QStyle::SC_TitleBarMaxButton;
}
}

QStyle::SCFlags under_mouse = QStyle::SC_None;
if( autoRaise() && hasMouse() ) {
QPoint p(mapFromGlobal(QCursor::pos()));
under_mouse = style().querySubControl(QStyle::CC_TitleBar, this, p);
ctrls ^= under_mouse;
}

QSharedDoubleBuffer buffer( this, rect() );
style().drawComplexControl(QStyle::CC_TitleBar, buffer.painter(), this, rect(),
colorGroup(),
isEnabled() ? QStyle::Style_Enabled :
QStyle::Style_Default, ctrls, d->buttonDown);
if(under_mouse != QStyle::SC_None)
style().drawComplexControl(QStyle::CC_TitleBar, buffer.painter(), this, rect(),
colorGroup(),
QStyle::Style_MouseOver |
(isEnabled() ? QStyle::Style_Enabled : 0),
under_mouse, d->buttonDown);
}



Note:
I have commit my code on http://sourceforge.net/projects/qt-webdav/ much tanks to wysota to make this projekt possibel.... the svn code is live update....

wysota
1st March 2007, 21:07
Why don't you just create an editor widget and assign it to the delegate for appropriate fields?

patrik08
1st March 2007, 21:33
Why don't you just create an editor widget and assign it to the delegate for appropriate fields?

An createEditor subclass .... is only to editable flag? or i write mistake?

i can test to emulate a Qt::ItemIsEditable; and return true (on set data ) to column 0 (zero) in this place wo i wand click action ....



QWidget *BaseDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (index.column() == 11 || index.column() == 7 ) {
QDateTimeEdit *editor = new QDateTimeEdit(parent);
editor->setDisplayFormat("dd.MM.yyyy");
editor->setCalendarPopup(true);
return editor;
} else {
return QItemDelegate::createEditor(parent, option, index);
}
}
void BaseDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
if (index.column() == 11 || index.column() == 7 ) {
QString dateuser = index.model()->data(index, Qt::DisplayRole).toString();
QDateTimeEdit *editorrun = qobject_cast<QDateTimeEdit *>(editor);
if (editorrun) {
editorrun->setDate(QDate::fromString(index.model()->data(index, Qt::EditRole).toString(), "dd.MM.yyyy"));
}
} else {
QItemDelegate::setEditorData(editor, index);
}
}



note: code paste from gedit not from scite \n\n buggi scite?
Help why i become "Advanced user" ?? :crying: i am advanced user on PHP5 Objekt programming , xml, xslt .... latex... but not on qt4.... on qt4 i preferred Intermediate....:rolleyes:

wysota
1st March 2007, 21:59
An createEditor subclass .... is only to editable flag? or i write mistake?
Yes and no. Under normal circumstances it is only for editable items but you can also open something what is called a persistent editor. It is an editor that is always active, regardless of the item focus.


i can test to emulate a Qt::ItemIsEditable; and return true (on set data ) to column 0 (zero) in this place wo i wand click action ....
I don't understand what you mean.



note: code paste from gedit not from scite \n\n buggi scite?
Again, I can't understand you.


Help why i become "Advanced user" ??

Because you post too much :)