Results 1 to 20 of 44

Thread: QItemDelegate Align

Hybrid View

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

    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

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

    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.

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

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

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

    Default Re: QItemDelegate Align

    for the code you have sent, problem is I have to create my action in createEditor()

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

    Default Re: QItemDelegate Align

    why do you have to do this?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Default Re: QItemDelegate Align

    problem is load create action acording to the values in other columns. for example,

    I have 3 rows and 6 columns

    for each row I get values of columns 1 and 3 and create an action for the toolbar in column 6 acording to this. If there is no value either in 1 and 3 there wont be any action

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

    Default Re: QItemDelegate Align

    so, I don't see any problem, make like this
    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.  
    22. QSpinBox *spinBox() const { return m_spinBox; }
    23. QToolButton *toolButton() const { return m_toolButton; }
    24.  
    25. public slots:
    26. void updateSpinBoxValue()
    27. {
    28. const QAction *action = qobject_cast<QAction *>(sender());
    29. if (!action)
    30. return;
    31.  
    32. m_spinBox->setValue(action->data().toInt());
    33. }
    34.  
    35. private:
    36. QSpinBox *m_spinBox;
    37. QToolButton *m_toolButton;
    38. };
    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.  
    6. MyComplexEditor *mce = new MyComplexEditor(parent);
    7. for (int i = 0; i < 4; ++i) {
    8. QAction *action = new QAction(tr("action%1").arg(i), mce);
    9. action->setData(i);
    10. mce->toolButton()->addAction(action);
    11. connect(action, SIGNAL(triggered()), mce, SLOT(updateSpinBoxValue()));
    12. }
    13. return mce;
    14. }
    To copy to clipboard, switch view to plain text mode 
    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, 19:21
  2. QItemDelegate
    By cyberboy in forum Qt Programming
    Replies: 10
    Last Post: 27th June 2008, 18:41
  3. Return a pointer from a QItemdelegate
    By SailinShoes in forum Qt Programming
    Replies: 5
    Last Post: 12th March 2008, 21:07
  4. premature call to setmodeldata with QItemDelegate
    By placebo in forum Qt Programming
    Replies: 1
    Last Post: 25th November 2007, 18:39
  5. QTextEdit Justify align making work
    By dec0ding in forum Qt Programming
    Replies: 2
    Last Post: 13th January 2006, 13: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.