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
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QItemDelegate Align

    can we do it with

    bool QLayout::setAlignment ( QWidget * w, Qt::Alignment alignment )???

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

    there is not necessary of using this method. all what you need it's to put all widget in right order. you need to use QHBoxLayout.
    but in this case your tool button will not be located on your editor, but it will be located on ther right of your spindox.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Default Re: QItemDelegate Align

    I was not able to use QHBoxLayout,

    When I use
    Qt Code:
    1. MyDoubleSpinBox2 *editor = new MyDoubleSpinBox2(parent);
    2.  
    3. QToolButton *tool;
    4. tool = new QToolButton();
    5. tool->setText("...");
    6.  
    7. QHBoxLayout layout;
    8. layout.addWidget(editor);
    9. layout.addWidget(tool);
    To copy to clipboard, switch view to plain text mode 

    I could not see tool button

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

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

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

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

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

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

    aekilic (24th March 2009)

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

  11. #10
    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].

  12. #11
    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?

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

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

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

    aekilic (24th March 2009)

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.