Results 1 to 20 of 44

Thread: QItemDelegate Align

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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

    wrong code. try this
    Qt Code:
    1. QWdiget *w = new QWidget(parent);
    2. MyDoubleSpinBox2 *editor = new MyDoubleSpinBox2();
    3.  
    4. QToolButton *tool = new QToolButton();
    5. tool->setText("...");
    6.  
    7. QHBoxLayout *layout = new QHBoxLayout(w);
    8. layout->addWidget(editor);
    9. layout->addWidget(tool);
    10.  
    11. return w;
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Default Re: QItemDelegate Align

    Dear spirit

    In this way, tool button located in the spin not near

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

    can show a screenshot?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Default Re: QItemDelegate Align

    in the attach
    Attached Images Attached Images

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

    this may work
    Qt Code:
    1. ...
    2. QWidget *w = new QWidget(parent);
    3. QSpinBox *sp = new QSpinBox();
    4. QHBoxLayout *hbl = new QHBoxLayout(w);
    5. sp->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    6. tb->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
    7. w->setFocusProxy(sp);
    8. hbl->setMargin(0);
    9. hbl->setSpacing(0);
    10.  
    11. hbl->addWidget(sp);
    12. hbl->addWidget(tb);
    13.  
    14. return w;
    15. ...
    16.  
    17. void ItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
    18. {
    19. Q_UNUSED(index);
    20. editor->setGeometry(option.rect);
    21. }
    To copy to clipboard, switch view to plain text mode 
    code updated.
    Last edited by spirit; 24th March 2009 at 10:04. Reason: updated contents
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. The following user says thank you to spirit for this useful post:

    aekilic (24th March 2009)

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

    Default Re: QItemDelegate Align

    this works great but we have a problem with

    Qt Code:
    1. void ProformaDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
    2. {
    3. QWidget *w = static_cast<MyDoubleSpinBox2*>(editor);
    4.  
    5. MyDoubleSpinBox2 *spinBox = static_cast<MyDoubleSpinBox2*>(w);
    6. spinBox->setValue(turkish.toDouble(index.model()->data(index, Qt::EditRole).toString().remove(totalParaBirimi, Qt::CaseInsensitive)));
    7. spinBox->selectAll();
    8. }
    To copy to clipboard, switch view to plain text mode 

    Can we do it like this?

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

    no, you can't do this. create your own widget which will return data.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Default Re: QItemDelegate Align

    himmmm

    how can I do it then?

  10. #9
    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

    the simpliest way
    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. QHBoxLayout *hbl = new QHBoxLayout(this);
    11. m_spinBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    12. m_toolButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
    13. setFocusProxy(m_spinBox);
    14. hbl->setMargin(0);
    15. hbl->setSpacing(0);
    16.  
    17. hbl->addWidget(m_spinBox);
    18. hbl->addWidget(m_toolButton);
    19. }
    20.  
    21. QSpinBox *spinBox() const { return m_spinBox; }
    22. QToolButton *toolButton() const { return m_toolButton; }
    23.  
    24. private:
    25. QSpinBox *m_spinBox;
    26. QToolButton *m_toolButton;
    27. };
    28.  
    29. ...
    30. void MyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    31. {
    32. return new MyComplexEditor(parent);
    33. }
    34.  
    35. void MyDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
    36. {
    37. MyComplexEditor *mce = qobject_cast<MyComplexEditor *>(editor);
    38. if (!mce)
    39. return;
    40. mce->spinBox()->setValue(turkish.toDouble(index.model()->data(index, Qt::EditRole).toString().remove(totalParaBirimi, Qt::CaseInsensitive)));
    41. mce->spinBox()->selectAll();
    42. }
    43. }
    To copy to clipboard, switch view to plain text mode 
    nothing complex, right?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  11. The following user says thank you to spirit for this useful post:

    aekilic (24th March 2009)

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

    Default Re: QItemDelegate Align

    Thank you very much problem solved, but was not complex

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

    Default Re: QItemDelegate Align

    I got one more question for the tool botton

    I create a action, and add to toolbotton.

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

    this slotenDusukAlis has to find something and put a number in a spin. But I was not able to work signal and slot can anybody help?

  14. #12
    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

    looks strange
    Qt Code:
    1. connect(enDusukAlis, SIGNAL(activated()), w->toolButton(), SLOT(slotenDusukAlis()));
    To copy to clipboard, switch view to plain text mode 
    QToolButton has not such slot slotenDusukAlis.
    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.