Results 1 to 6 of 6

Thread: QSqlRelationalDelegate Draw a clickable QToolButton

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QSqlRelationalDelegate Draw a clickable QToolButton

    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....




    Qt Code:
    1. void BaseDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3. /////////qDebug() << "### index-column " << index.column();
    4.  
    5. if (index.column() == 0) {
    6. /* not on edit only flags |= Qt::ItemIsSelectable; */
    7. QString numer = index.model()->data(index, Qt::DisplayRole).toString();
    8. QString text = QString("(%1)").arg(numer);
    9. QToolButton * button1 = new QToolButton(tas);
    10. button1->setText(text);
    11. tas->setIndexWidget(index,button1);
    12. } else if (index.column() == 1) {
    13. /* not on edit only flags |= Qt::ItemIsSelectable; */
    14. QString coder = index.model()->data(index, Qt::DisplayRole).toString();
    15. QStyleOptionViewItem myOption = option;
    16. myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
    17. myOption.palette.setColor( QPalette::Text , Qt::red );
    18. drawDisplay(painter, myOption, myOption.rect,coder);
    19. drawFocus(painter, myOption, myOption.rect);
    20.  
    21. }
    22. ...............
    23.  
    24.  
    25. }
    26.  
    27. /* header */
    28.  
    29. class BaseDelegate : public QSqlRelationalDelegate
    30. {
    31. Q_OBJECT
    32.  
    33. public:
    34. BaseDelegate( QTableView *ta , QObject *parent );
    35. void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    36. QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    37. void setEditorData(QWidget *editor, const QModelIndex &index) const;
    38. void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
    39. private slots:
    40. private:
    41. QTableView *tas;
    42.  
    43. };
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlRelationalDelegate Draw a clickable QToolButton

    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?

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSqlRelationalDelegate Draw a clickable QToolButton

    Quote Originally Posted by wysota View Post
    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/fidE11AA04...ComplexControl

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




    Qt Code:
    1. void QTitleBar::paintEvent(QPaintEvent *)
    2. {
    3. QStyle::SCFlags ctrls = QStyle::SC_TitleBarLabel;
    4. if ( testWFlags( WStyle_SysMenu) ) {
    5. if ( testWFlags( WStyle_Tool ) ) {
    6. ctrls |= QStyle::SC_TitleBarCloseButton;
    7. if ( d->window && testWFlags( WStyle_MinMax ) ) {
    8. if ( d->window->isMinimized() )
    9. ctrls |= QStyle::SC_TitleBarUnshadeButton;
    10. else
    11. ctrls |= QStyle::SC_TitleBarShadeButton;
    12. }
    13. } else {
    14. ctrls |= QStyle::SC_TitleBarSysMenu | QStyle::SC_TitleBarCloseButton;
    15. if ( d->window && testWFlags( WStyle_Minimize ) ) {
    16. if( d->window && d->window->isMinimized() )
    17. ctrls |= QStyle::SC_TitleBarNormalButton;
    18. else
    19. ctrls |= QStyle::SC_TitleBarMinButton;
    20. }
    21. if ( d->window && testWFlags( WStyle_Maximize ) && !d->window->isMaximized() )
    22. ctrls |= QStyle::SC_TitleBarMaxButton;
    23. }
    24. }
    25.  
    26. QStyle::SCFlags under_mouse = QStyle::SC_None;
    27. if( autoRaise() && hasMouse() ) {
    28. QPoint p(mapFromGlobal(QCursor::pos()));
    29. under_mouse = style().querySubControl(QStyle::CC_TitleBar, this, p);
    30. ctrls ^= under_mouse;
    31. }
    32.  
    33. QSharedDoubleBuffer buffer( this, rect() );
    34. style().drawComplexControl(QStyle::CC_TitleBar, buffer.painter(), this, rect(),
    35. colorGroup(),
    36. isEnabled() ? QStyle::Style_Enabled :
    37. QStyle::Style_Default, ctrls, d->buttonDown);
    38. if(under_mouse != QStyle::SC_None)
    39. style().drawComplexControl(QStyle::CC_TitleBar, buffer.painter(), this, rect(),
    40. colorGroup(),
    41. QStyle::Style_MouseOver |
    42. (isEnabled() ? QStyle::Style_Enabled : 0),
    43. under_mouse, d->buttonDown);
    44. }
    To copy to clipboard, switch view to plain text mode 

    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....

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlRelationalDelegate Draw a clickable QToolButton

    Why don't you just create an editor widget and assign it to the delegate for appropriate fields?

  5. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSqlRelationalDelegate Draw a clickable QToolButton

    Quote Originally Posted by wysota View Post
    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 ....

    Qt Code:
    1. QWidget *BaseDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3. if (index.column() == 11 || index.column() == 7 ) {
    4. QDateTimeEdit *editor = new QDateTimeEdit(parent);
    5. editor->setDisplayFormat("dd.MM.yyyy");
    6. editor->setCalendarPopup(true);
    7. return editor;
    8. } else {
    9. return QItemDelegate::createEditor(parent, option, index);
    10. }
    11. }
    12. void BaseDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
    13. {
    14. if (index.column() == 11 || index.column() == 7 ) {
    15. QString dateuser = index.model()->data(index, Qt::DisplayRole).toString();
    16. QDateTimeEdit *editorrun = qobject_cast<QDateTimeEdit *>(editor);
    17. if (editorrun) {
    18. editorrun->setDate(QDate::fromString(index.model()->data(index, Qt::EditRole).toString(), "dd.MM.yyyy"));
    19. }
    20. } else {
    21. QItemDelegate::setEditorData(editor, index);
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

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

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlRelationalDelegate Draw a clickable QToolButton

    Quote Originally Posted by patrik08 View Post
    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

Similar Threads

  1. Replies: 5
    Last Post: 7th November 2006, 15:01
  2. Using QGLWidget paint engine to draw regular widgtes?
    By high_flyer in forum Qt Programming
    Replies: 11
    Last Post: 9th October 2006, 12:06
  3. Draw QtCanvasElipse on mouse press event position
    By YuriyRusinov in forum Newbie
    Replies: 1
    Last Post: 31st May 2006, 11:57
  4. Howto draw stuff
    By Morea in forum Newbie
    Replies: 16
    Last Post: 7th April 2006, 12:05
  5. Drawing over content widgets? (overlay)
    By sertrem in forum Qt Programming
    Replies: 2
    Last Post: 17th January 2006, 22:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.