Results 1 to 4 of 4

Thread: QSqlRelationalDelegate not display my QWidget, only onclick

  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 not display my QWidget, only onclick

    I want to display a button on my table ....

    how i must set paint ?... to display direct QWidget ... not only on click.....

    if (index.column() == 0) {
    int xnummer = index.model()->data(index, Qt:isplayRole).toInt();
    this->createEditor(tas, option, index);

    }






    Qt Code:
    1. BaseDelegate::BaseDelegate( QTableView *ta , QObject *parent )
    2. {
    3. tas = ta;
    4. }
    5.  
    6. void BaseDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    7. {
    8. /////////qDebug() << "### index-column " << index.column();
    9.  
    10. if (index.column() == 0) {
    11. int xnummer = index.model()->data(index, Qt::DisplayRole).toInt();
    12. this->createEditor(tas, option, index);
    13.  
    14. } else if (index.column() == 1) {
    15. QString coder = index.model()->data(index, Qt::DisplayRole).toString();
    16. QStyleOptionViewItem myOption = option;
    17. myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
    18. myOption.palette.setColor( QPalette::Text , Qt::red );
    19. drawDisplay(painter, myOption, myOption.rect,coder);
    20. drawFocus(painter, myOption, myOption.rect);
    21.  
    22. } else if (index.column() == 8) {
    23. QString anno = index.model()->data(index, Qt::DisplayRole).toString();
    24. //////////////QString coda = BerufHuman(coder);
    25. QStyleOptionViewItem myOption = option;
    26. myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
    27. if (anno !="0") {
    28. myOption.palette.setColor( QPalette::Text , Qt::gray );
    29. } else {
    30. myOption.palette.setColor( QPalette::Text , Qt::white );
    31. }
    32. drawDisplay(painter, myOption, myOption.rect,anno);
    33. drawFocus(painter, myOption, myOption.rect);
    34.  
    35. } else{
    36. QItemDelegate::paint(painter, option, index);
    37. }
    38. }
    39.  
    40. QWidget *BaseDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    41. {
    42. if (index.column() == 11 || index.column() == 7 ) {
    43. QDateTimeEdit *editor = new QDateTimeEdit(parent);
    44. editor->setDisplayFormat("dd.MM.yyyy");
    45. editor->setCalendarPopup(true);
    46. return editor;
    47. } else if (index.column() == 0) {
    48. Base_Button *editora = new Base_Button(parent);
    49. return editora;
    50. } else {
    51. return QItemDelegate::createEditor(parent, option, index);
    52. }
    53. }
    54.  
    55. void BaseDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
    56. {
    57.  
    58. if (index.column() == 11 || index.column() == 7 ) {
    59. QString dateuser = index.model()->data(index, Qt::DisplayRole).toString();
    60. QDateTimeEdit *editorrun = qobject_cast<QDateTimeEdit *>(editor);
    61. if (editorrun) {
    62. editorrun->setDate(QDate::fromString(index.model()->data(index, Qt::EditRole).toString(), "dd.MM.yyyy"));
    63. }
    64.  
    65. } else if (index.column() == 0) {
    66. int xnummer = index.model()->data(index, Qt::DisplayRole).toInt();
    67. Base_Button *editorax = qobject_cast<Base_Button *>(editor);
    68. editorax->SetNummer(xnummer);
    69. } else {
    70. QItemDelegate::setEditorData(editor, index);
    71. }
    72. }
    73.  
    74. void BaseDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
    75. {
    76. if (index.column() == 11 || index.column() == 7 ) {
    77. QDateTimeEdit *dateEditor = qobject_cast<QDateTimeEdit *>(editor);
    78. if (dateEditor) {
    79. model->setData(index,dateEditor->date().toString("dd.MM.yyyy"));
    80. }
    81. } else if (index.column() == 0) {
    82. Base_Button *editorax = qobject_cast<Base_Button *>(editor);
    83. model->setData(index,editorax->GetNummer());
    84. } else {
    85. QItemDelegate::setModelData(editor, model, index);
    86. }
    87. }
    88.  
    89.  
    90. class Base_Button: public QWidget
    91. {
    92. Q_OBJECT
    93. //
    94. public:
    95. QPushButton *pushButton;
    96.  
    97. Base_Button( QWidget *parent )
    98. : QWidget(parent)
    99. {
    100. setAttribute(Qt::WA_WindowPropagation);
    101. QVBoxLayout *widgetLayout = new QVBoxLayout(this);
    102. widgetLayout->setMargin(0);
    103. widgetLayout->setSpacing(0);
    104. pushButton = new QPushButton(this);
    105. pushButton->setText(tr("Edit Nr. 0"));
    106. widgetLayout->addWidget(pushButton);
    107. }
    108. void SetNummer( int numero ) {
    109. identificativo = numero;
    110. pushButton->setText(tr("Edit Nr. %1").arg(identificativo));
    111. }
    112. int GetNummer() {
    113. return identificativo;
    114. }
    115. private:
    116. int identificativo;
    117. QSize sizebase;
    118. protected:
    119. signals:
    120. public slots:
    121.  
    122. };
    123.  
    124.  
    125. class BaseDelegate : public QSqlRelationalDelegate
    126. {
    127. Q_OBJECT
    128.  
    129. public:
    130. BaseDelegate( QTableView *ta , QObject *parent );
    131. void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    132. QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    133. void setEditorData(QWidget *editor, const QModelIndex &index) const;
    134. void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
    135. private slots:
    136. private:
    137. QTableView *tas;
    138. QObject *sap;
    139.  
    140. };
    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 not display my QWidget, only onclick

    Either use setIndexWidget or openPersistentEditor.

  3. The following user says thank you to wysota for this useful post:

    patrik08 (8th March 2007)

  4. #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 not display my QWidget, only onclick

    Quote Originally Posted by wysota View Post
    Either use setIndexWidget or openPersistentEditor.

    Super . ... You have answer for all qt question! if You have answer for all theme this is Danger!!!

    Qt Code:
    1. void BaseDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3.  
    4.  
    5. if (index.column() == 0) { /* tas parent qtablewiev*/
    6. tas->setColumnWidth (0,105);
    7. tas->openPersistentEditor(index);
    8. return;
    9. } else if (index.column() == 1) {
    10. QString coder = index.model()->data(index, Qt::DisplayRole).toString();
    11. QStyleOptionViewItem myOption = option;
    12. myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
    13. myOption.palette.setColor( QPalette::Text , Qt::red );
    14. drawDispl..........................
    To copy to clipboard, switch view to plain text mode 

  5. #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 not display my QWidget, only onclick

    Just please don't paste so much unrelevant code in your posts (like in the first post in this thread). Nobody will read it anyway, so there is no point posting it. If you want to include some code, then make it as short (and simple) as possible.

Similar Threads

  1. Replies: 8
    Last Post: 18th March 2011, 11:27
  2. QTextEdit, sizeHint, QWidget
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 3rd February 2007, 08:25
  3. How to Read and display BMP image using QT
    By agsrinivasan in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2007, 07:14
  4. QWidget display on 2 stack widget page
    By spawnwj in forum Qt Programming
    Replies: 3
    Last Post: 4th September 2006, 12:07
  5. Replies: 1
    Last Post: 2nd May 2006, 21:11

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.