Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 44

Thread: QItemDelegate Align

  1. #21
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Align

    What I use is,

    Qt Code:
    1. QAction *enDusukAlis = new QAction(QString::fromUtf8("En DüşÃ¼k Alış Fiyatı"), w->toolButton());
    2. connect(enDusukAlis, SIGNAL(activated()), this, SLOT(slotenDusukAlis()));
    3. w->toolButton()->addAction(enDusukAlis);
    To copy to clipboard, switch view to plain text mode 

    But the signal doesnt work

  2. #22
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QItemDelegate Align

    A QAction has only the signals:
    void changed ()
    void hovered ()
    void toggled ( bool checked )
    void triggered ( bool checked = false )
    void destroyed ( QObject * obj = 0 )

    No activated!

  3. #23
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QItemDelegate Align

    yup, Qt Assistant -- rocks!
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  4. #24
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Align

    Quote Originally Posted by spirit View Post
    yup, Qt Assistant -- rocks!
    yes, it really rocks!

    For the setData how can I use it then?

  5. #25
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Align

    Qt Code:
    1. .....
    2. QAction *enDusukSatis = new QAction(QString::fromUtf8("En DüşÃ¼k Satış Fiyatı"), w->toolButton());
    3. connect(enDusukSatis, SIGNAL(triggered()), this, SLOT(test()));
    4. w->toolButton()->addAction(enDusukSatis);
    5. .....
    6. void ProformaDelegate::test()
    7. {
    8. QMessageBox::warning(0, QString::fromUtf8("HATA"),
    9. QString::fromUtf8("İşlemde bir hata oluştu \nLütfen tekrar deneyiniz \nveya \nSistem uzmanına başvurunuz"));
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    But the signal doent work...

  6. #26
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QItemDelegate Align

    everything should work, press and hold a tool button, a popup menu should appear with your action. if you want slot is being called immediately then
    Qt Code:
    1. connect(w->toolButton(), SIGNAL(clicked()), this, SLOT(test()));
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #27
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Align

    Dear Spirit

    Qt Code:
    1. connect(w->toolButton(), SIGNAL(clicked()), this, SLOT(test()));
    To copy to clipboard, switch view to plain text mode 

    also doesnt work

  8. #28
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QItemDelegate Align

    Then show us your (whole) code. Maybe Q_OBJECT forgotten? Do you get a warning?

  9. #29
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QItemDelegate Align

    what does this operation show in console?
    Qt Code:
    1. qDebug() << connect(w->toolButton(), SIGNAL(clicked()), this, SLOT(test()));
    To copy to clipboard, switch view to plain text mode 
    did you add Q_OBJECT macro in your class declaration.
    PS. I've just tested both of these approaches and they work fine for me.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  10. #30
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Align

    h.h

    Qt Code:
    1. class ProformaDelegate : public QItemDelegate
    2. {
    3. Q_OBJECT
    4.  
    5. QString totalParaBirimi;
    6. public:
    7. ProformaDelegate(QObject *parent = 0, const QString &paraBirimi = QString::null);
    8.  
    9. QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
    10. const QModelIndex &index) const;
    11.  
    12. void setEditorData(QWidget *editor, const QModelIndex &index) const;
    13. void setModelData(QWidget *editor, QAbstractItemModel *model,
    14. const QModelIndex &index) const;
    15. void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    16.  
    17. void test();
    18. private:
    19. QWidget *m_handler;
    20.  
    21. };
    22.  
    23. class MyComplexEditor: public QWidget
    24. {
    25. Q_OBJECT
    26.  
    27. public:
    28. MyComplexEditor(QWidget *parent = 0) : QWidget(parent)
    29. {
    30. m_spinBox = new MyDoubleSpinBox2();
    31.  
    32.  
    33.  
    34. m_toolButton = new QToolButton();
    35.  
    36. QHBoxLayout *hbl = new QHBoxLayout(this);
    37. m_spinBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    38. m_toolButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
    39. setFocusProxy(m_spinBox);
    40. hbl->setMargin(0);
    41. hbl->setSpacing(0);
    42.  
    43. hbl->addWidget(m_spinBox);
    44. hbl->addWidget(m_toolButton);
    45. }
    46. void slotenDusukAlis()
    47. {
    48. QMessageBox::warning(0, QString::fromUtf8("HATA"),
    49. QString::fromUtf8("İşlemde bir hata oluştu \nLütfen tekrar deneyiniz \nveya \nSistem uzmanına başvurunuz"));
    50. }
    51. MyDoubleSpinBox2 *spinBox() const { return m_spinBox; }
    52. QToolButton *toolButton() const { return m_toolButton; }
    53.  
    54. private:
    55. MyDoubleSpinBox2 *m_spinBox;
    56. QToolButton *m_toolButton;
    57. };
    58.  
    59. #endif
    To copy to clipboard, switch view to plain text mode 

    h.cpp

    Qt Code:
    1. #include "proformaDelegate.h"
    2. #include "libs/Delegate/myDoubleSpinBox.h"
    3.  
    4.  
    5. ProformaDelegate::ProformaDelegate(QObject *parent, const QString &paraBirimi): QItemDelegate(parent)
    6. {
    7.  
    8. }
    9. QString gosteri = "%L1";
    10.  
    11.  
    12. QWidget *ProformaDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    13. {
    14. QLocale::setDefault(QLocale(QLocale::Turkish, QLocale::Turkey));
    15.  
    16. if(index.column() == 5)
    17. {
    18. MyComplexEditor *w = new MyComplexEditor(parent);
    19.  
    20. w->spinBox()->setMinimum(0);
    21. w->spinBox()->setMaximum(4000000000);
    22. w->spinBox()->setDecimals(4);
    23. w->spinBox()->setSuffix(" " + totalParaBirimi);
    24. w->spinBox()->setAlignment(Qt::AlignRight);
    25. w->spinBox()->setButtonSymbols(QAbstractSpinBox::NoButtons);
    26. w->spinBox()->selectAll();
    27.  
    28. w->toolButton()->setText("...");
    29. w->toolButton()->setPopupMode(QToolButton::InstantPopup);
    30.  
    31.  
    32. QAction *enDusukSatis = new QAction(QString::fromUtf8("En DüşÃ¼k Satış Fiyatı"), w->toolButton());
    33. connect(enDusukSatis, SIGNAL(trigger()), this, SLOT(test()));
    34. w->toolButton()->addAction(enDusukSatis);
    35.  
    36.  
    37. connect(w->toolButton(), SIGNAL(clicked()), this, SLOT(test()));
    38.  
    39. QAction *enOrtAlis = new QAction(QString::fromUtf8("Ortalama Alış Fiyatı"), w->toolButton());
    40. connect(enOrtAlis, SIGNAL(activated()), w->toolButton(), SLOT(slotenOrtAlis()));
    41. w->toolButton()->addAction(enOrtAlis);
    42.  
    43. QAction *enOrtSatis = new QAction(QString::fromUtf8("Ortalama Alış Fiyatı"), w->toolButton());
    44. connect(enOrtSatis, SIGNAL(activated()), w->toolButton(), SLOT(slotenOrtSatis()));
    45. w->toolButton()->addAction(enOrtSatis);
    46.  
    47. QAction *enYuksAlis = new QAction(QString::fromUtf8("En Yüksek Alış Fiyatı"), w->toolButton());
    48. connect(enYuksAlis, SIGNAL(activated()), w->toolButton(), SLOT(slotenYuksAlis()));
    49. w->toolButton()->addAction(enYuksAlis);
    50.  
    51. QAction *enYuksSatis = new QAction(QString::fromUtf8("En Yüksek Satış Fiyatı"), w->toolButton());
    52. connect(enYuksSatis, SIGNAL(activated()), w->toolButton(), SLOT(slotenYuksSatis()));
    53. w->toolButton()->addAction(enYuksSatis);
    54.  
    55. QAction *enSonAlis = new QAction(QString::fromUtf8("Son Alış fiyatı"), w->toolButton());
    56. connect(enSonAlis, SIGNAL(activated()), w->toolButton(), SLOT(slotenSonAlis()));
    57. w->toolButton()->addAction(enSonAlis);
    58.  
    59. QAction *enSonSatis = new QAction(QString::fromUtf8("Son Satış fiyatı"), w->toolButton());
    60. connect(enSonSatis, SIGNAL(activated()), w->toolButton(), SLOT(slotenSonSatis()));
    61. w->toolButton()->addAction(enSonSatis);
    62.  
    63. /* En DüşÃ¼k Alış Fiyatı
    64. En DüşÃ¼k Satış Fiyatı
    65. Ortalama Alış Fiyatı
    66. Ortalama Satış Fiyatı
    67. En Yüksek Alış Fiyatı
    68. En Yüksek Satış Fiyatı
    69. Son Alış fiyatı
    70. Son Satış fiyatı*/
    71.  
    72.  
    73. QSqlQuery markaid_q;
    74. markaid_q.exec("SELECT markaid FROM stokdakiler WHERE stokdakilerid = '" + index.model()->data(index.sibling(index.row(), 2), Qt::StatusTipRole).toString() + "';");
    75. markaid_q.next();
    76.  
    77. QSqlQuery fiyat_tipleri;
    78. fiyat_tipleri.exec("SELECT id, stokid, markaid, fiyat_tipleri.fiyat_tipi || ' (' || kurcinsi || ') ' || fiyat, fili_fiyat FROM stokdakiler_fiyat "
    79. "LEFT JOIN fiyat_tipleri ON fiyat_tipleri.fiyat_tipi_id = stokdakiler_fiyat.fiyat_tip "
    80. "LEFT JOIN kur ON kur.kurid = stokdakiler_fiyat.kur_id "
    81. "WHERE markaid = '" + markaid_q.value(0).toString() + "' AND "
    82. "stokid = '" + index.model()->data(index.sibling(index.row(), 1), Qt::StatusTipRole).toString() + "';");
    83. int i = 0;
    84. while(fiyat_tipleri.next()){
    85. // QMessageBox::warning(0, QString::fromUtf8("HATA"),
    86. // QString::fromUtf8("İşlemde bir hata oluştu \nLütfen tekrar deneyiniz \nveya \nSistem uzmanına başvurunuz"));
    87. QAction *cutAction = new QAction(fiyat_tipleri.value(3).toString(), w->toolButton());
    88. w->toolButton()->addAction(cutAction);
    89. ++i;
    90. // sayi = i;
    91. }
    92.  
    93.  
    94. // return new MyComplexEditor(parent);
    95. return w;
    96.  
    97. }
    98.  
    99. return 0;
    100. }
    101. void ProformaDelegate::test()
    102. {
    103. QMessageBox::warning(0, QString::fromUtf8("HATA"),
    104. QString::fromUtf8("İşlemde bir hata oluştu \nLütfen tekrar deneyiniz \nveya \nSistem uzmanına başvurunuz"));
    105.  
    106. }
    107.  
    108. void ProformaDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
    109. {
    110. Q_UNUSED(index);
    111. editor->setGeometry(option.rect);
    112. }
    113. void ProformaDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
    114. {
    115. QLocale turkish(QLocale::Turkish);
    116.  
    117. if(index.column() == 5)
    118. {
    119. MyComplexEditor *mce = qobject_cast<MyComplexEditor *>(editor);
    120. if (!mce)
    121. return;
    122. mce->spinBox()->setValue(turkish.toDouble(index.model()->data(index, Qt::EditRole).toString().remove(totalParaBirimi, Qt::CaseInsensitive)));
    123. mce->spinBox()->selectAll();
    124. }
    125. }
    126.  
    127. void ProformaDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
    128. const QModelIndex &index) const
    129. {
    130. QLocale turkish(QLocale::Turkish);
    131.  
    132. if(index.column() == 5)
    133. {
    134. MyComplexEditor *mce = static_cast<MyComplexEditor *>(editor);
    135. if (!mce)
    136. return;
    137. model->setData(index, gosteri.arg(mce->spinBox()->value(),0,'f',2) + " " + totalParaBirimi, Qt::DisplayRole);
    138.  
    139. }
    140.  
    141. }
    To copy to clipboard, switch view to plain text mode 

  11. #31
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QItemDelegate Align

    come on void test() it's not a slot
    do this.
    Qt Code:
    1. private slots:
    2. void test();
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  12. #32
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Align

    Dear Spirit

    I put it in
    Qt Code:
    1. private slots:
    2. void test();
    To copy to clipboard, switch view to plain text mode 

    but notting changed

  13. #33
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QItemDelegate Align

    works perfectly
    cpp
    Qt Code:
    1. QWidget *ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3. Q_UNUSED(option);
    4. Q_UNUSED(index);
    5.  
    6. MyComplexEditor *mce = new MyComplexEditor(parent);
    7.  
    8. QAction *enDusukSatis = new QAction("test", mce->toolButton());
    9. connect(enDusukSatis, SIGNAL(triggered()), SLOT(test()));
    10. mce->toolButton()->addAction(enDusukSatis);
    11. //connect(mce->toolButton(), SIGNAL(clicked()), SLOT(test()));
    12.  
    13. return mce;
    14. }
    15.  
    16. void ItemDelegate::test()
    17. {
    18. QMessageBox::information(0, tr("information"), tr("test"));
    19. }
    20.  
    21. void ItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
    22. {
    23. Q_UNUSED(index);
    24. editor->setGeometry(option.rect);
    25. }
    To copy to clipboard, switch view to plain text mode 
    h
    Qt Code:
    1. class MyComplexEditor: public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. MyComplexEditor(QWidget *parent = 0) : QWidget(parent)
    7. {
    8. m_spinBox = new QSpinBox();
    9. m_toolButton = new QToolButton();
    10. m_toolButton->setText("...");
    11. QHBoxLayout *hbl = new QHBoxLayout(this);
    12. m_spinBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    13. m_toolButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
    14. setFocusProxy(m_spinBox);
    15. hbl->setMargin(0);
    16. hbl->setSpacing(0);
    17.  
    18. hbl->addWidget(m_spinBox);
    19. hbl->addWidget(m_toolButton);
    20. }
    21.  
    22. QSpinBox *spinBox() const { return m_spinBox; }
    23. QToolButton *toolButton() const { return m_toolButton; }
    24.  
    25. private:
    26. QSpinBox *m_spinBox;
    27. QToolButton *m_toolButton;
    28. };
    29. //-------------------------------------------------
    30. class ItemDelegate: public QItemDelegate
    31. {
    32. Q_OBJECT
    33.  
    34. public:
    35. virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    36. virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    37.  
    38. private slots:
    39. void test();
    40. };
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  14. #34
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Align

    Dear Spirit

    Thank you very much for all your help, not I have work out everything but only problem I have is

    I get the data loaded on the actiong like this,

    Qt Code:
    1. QAction *action = qobject_cast<QAction *>(sender());
    2. if (action)
    3. {
    4. birimFiyat = action->data().toDouble();
    5. }
    To copy to clipboard, switch view to plain text mode 

    But I need the double to be in
    Qt Code:
    1. void ProformaDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
    2. const QModelIndex &index) const
    3. {
    4. MyComplexEditor *mce = static_cast<MyComplexEditor *>(editor);
    5. if (!mce)
    6. return;
    7. model->setData(index, gosteri.arg(birimFiyat,0,'f',2) + " " + totalParaBirimi, Qt::DisplayRole);
    8. }
    To copy to clipboard, switch view to plain text mode 


    Can any body help?

  15. #35
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QItemDelegate Align

    I don't understand why do you need that action?
    you need to get data prom spinbox by pressing tool button, right?
    if yes, then I don't see any sense of using action, just process clicked signal of tool button and then in a slot do next
    Qt Code:
    1. ...
    2. emit commitData(widget);
    3. emit closeEditor(widget, QAbstractItemDelegate::SubmitModelCache);
    4. ...
    To copy to clipboard, switch view to plain text mode 
    where widget it's you complex widget.
    so, try this
    Qt Code:
    1. QWidget *ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3. Q_UNUSED(option);
    4. Q_UNUSED(index);
    5.  
    6. MyComplexEditor *mce = new MyComplexEditor(parent);
    7. connect(mce->toolButton(), SIGNAL(clicked()), SLOT(test()));
    8.  
    9. return mce;
    10. }
    11.  
    12. void ItemDelegate::test()
    13. {
    14. QMessageBox::information(0, tr("information"), tr("test"));
    15. QToolButton *toolButton = qobject_cast<QToolButton *>(sender());
    16. if (!toolButton)
    17. return;
    18. MyComplexEditor *mce = qobject_cast<MyComplexEditor *>(toolButton->parentWidget());
    19. if (!mce)
    20. return;
    21. emit commitData(mce);
    22. emit closeEditor(mse, QAbstractItemDelegate::SubmitModelCache);
    23. }
    To copy to clipboard, switch view to plain text mode 
    after that setModelData will be called and data will be set in model.
    btw, you don't need to chage this method setModelData leave it as is.
    hope this helps.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  16. #36
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Align

    No I need the action because I bring the actions from sql amd evey action has a different number which I set them by setData.

    I need to set those numbers to spin when I select from tool.

  17. #37
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QItemDelegate Align

    sigh, then you need:
    1. add actions in complex editor
    2. create needed connection
    3. process triggered signals
    4. set values in spinbox.

    then you need modify you delegate in this way:
    1. remove connect(mce->toolButton(), SIGNAL(clicked()), SLOT(test()));
    2. remove test slot.
    3. leave setModelData as is.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  18. #38
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Align

    I have tried this

    Qt Code:
    1. connect(recentFileActs[i], SIGNAL(triggered()), this, SLOT(w->spinBox()->setValue(fiyat_tipleri.value(4).toDouble())));
    To copy to clipboard, switch view to plain text mode 

    But it didnt work

  19. #39
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Align

    you can't connect signal to a slot when signal has less number of parameters than slot wants to get. Because from where that slot should take those missing arguments?
    and SLOT(asd()) uses asd() as "asd()" character string (or even something like "2asd()" or more complicated :]), not a function call.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  20. #40
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QItemDelegate Align

    Quote Originally Posted by aekilic View Post
    I have tried this

    Qt Code:
    1. connect(recentFileActs[i], SIGNAL(triggered()), this, SLOT(w->spinBox()->setValue(fiyat_tipleri.value(4).toDouble())));
    To copy to clipboard, switch view to plain text mode 

    But it didnt work
    pretty wrong code.
    ok, that's a new variant
    h-file
    Qt Code:
    1. class MyComplexEditor: public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. MyComplexEditor(QWidget *parent = 0) : QWidget(parent)
    7. {
    8. m_spinBox = new QSpinBox();
    9. m_toolButton = new QToolButton();
    10. m_toolButton->setText("...");
    11. QHBoxLayout *hbl = new QHBoxLayout(this);
    12. m_spinBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    13. m_toolButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
    14. setFocusProxy(m_spinBox);
    15. hbl->setMargin(0);
    16. hbl->setSpacing(0);
    17.  
    18. hbl->addWidget(m_spinBox);
    19. hbl->addWidget(m_toolButton);
    20.  
    21. for (int i = 0; i < 4; ++i) {
    22. QAction *action = new QAction(tr("action%1").arg(i), this);
    23. action->setData(i);
    24. m_toolButton->addAction(action);
    25. connect(action, SIGNAL(triggered()), SLOT(updateSpinBoxValue()));
    26. }
    27. }
    28.  
    29. QSpinBox *spinBox() const { return m_spinBox; }
    30. QToolButton *toolButton() const { return m_toolButton; }
    31.  
    32. private slots:
    33. void updateSpinBoxValue()
    34. {
    35. const QAction *action = qobject_cast<QAction *>(sender());
    36. if (!action)
    37. return;
    38.  
    39. m_spinBox->setValue(action->data().toInt());
    40. }
    41.  
    42. private:
    43. QSpinBox *m_spinBox;
    44. QToolButton *m_toolButton;
    45. };
    To copy to clipboard, switch view to plain text mode 
    cpp-file
    Qt Code:
    1. QWidget *ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3. Q_UNUSED(option);
    4. Q_UNUSED(index);
    5. return new MyComplexEditor(parent);
    6. }
    7.  
    8. void ItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
    9. {
    10. MyComplexEditor *mce = qobject_cast<MyComplexEditor *>(editor);
    11. if (!mce)
    12. return;
    13. model->setData(index, mce->spinBox()->value());
    14. }
    To copy to clipboard, switch view to plain text mode 
    select one of action and close editor (click on another item), data in cell will be stored to model.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Help needed with QItemDelegate
    By cyberboy in forum Qt Programming
    Replies: 3
    Last Post: 9th July 2008, 18:21
  2. QItemDelegate
    By cyberboy in forum Qt Programming
    Replies: 10
    Last Post: 27th June 2008, 17:41
  3. Return a pointer from a QItemdelegate
    By SailinShoes in forum Qt Programming
    Replies: 5
    Last Post: 12th March 2008, 20:07
  4. premature call to setmodeldata with QItemDelegate
    By placebo in forum Qt Programming
    Replies: 1
    Last Post: 25th November 2007, 17:39
  5. QTextEdit Justify align making work
    By dec0ding in forum Qt Programming
    Replies: 2
    Last Post: 13th January 2006, 12:02

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
  •  
Qt is a trademark of The Qt Company.