Page 1 of 3 123 LastLast
Results 1 to 20 of 44

Thread: QItemDelegate Align

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

    Default QItemDelegate Align

    Dear All

    We have a problem,
    Qt Code:
    1. MyDoubleSpinBox2 *editor = new MyDoubleSpinBox2(parent);
    2.  
    3. QToolButton *tool;
    4. tool = new QToolButton(editor);
    5. tool->setText("...");
    6.  
    7. return editor;
    To copy to clipboard, switch view to plain text mode 

    When we do this we get the tool button on left, how we could get the button on right?

  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

    try to use QWidget::setGeometry or QWidget::move. but anyway when editor is being resized you need to move your tool button to new position. so, you can process QResizeEvent of your editor and update tool button position. another way it's to put your editor and tool button in layout.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QItemDelegate Align

    Move it there using QWidget API.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    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 )???

  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

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

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

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

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

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

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

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

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

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

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

    aekilic (24th March 2009)

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

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

  15. #14
    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?

  16. #15
    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].

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

    aekilic (24th March 2009)

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

  19. #17
    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?

  20. #18
    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].

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

    Default Re: QItemDelegate Align

    Dear All

    What I need to do is,

    I have QAction's on the QToolMenu,

    Like
    Best Price '10'
    Low Price '8'

    What I need to do is, after user select Best Price '10' I need to put 10 to the spin...

    Am I able to explain?

  22. #20
    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) use QRegExp to extract the number of the displayed text
    or better
    b) use QAction::setData() to store your number while generating the QActions

    use the QToolButton::triggered ( QAction * action ) signal.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.