Page 3 of 3 FirstFirst 123
Results 41 to 44 of 44

Thread: QItemDelegate Align

  1. #41
    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()

  2. #42
    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].

  3. #43
    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

  4. #44
    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, 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.