Dear All
We have a problem,
Code:
MyDoubleSpinBox2 *editor = new MyDoubleSpinBox2(parent); QToolButton *tool; tool->setText("..."); return editor;
When we do this we get the tool button on left, how we could get the button on right?
Printable View
Dear All
We have a problem,
Code:
MyDoubleSpinBox2 *editor = new MyDoubleSpinBox2(parent); QToolButton *tool; tool->setText("..."); return editor;
When we do this we get the tool button on left, how we could get the button on right?
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.
Move it there using QWidget API.
can we do it with
bool QLayout::setAlignment ( QWidget * w, Qt::Alignment alignment )???
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.
I was not able to use QHBoxLayout,
When I use
Code:
MyDoubleSpinBox2 *editor = new MyDoubleSpinBox2(parent); QToolButton *tool; tool->setText("..."); QHBoxLayout layout; layout.addWidget(editor); layout.addWidget(tool);
I could not see tool button
wrong code. try this
Code:
MyDoubleSpinBox2 *editor = new MyDoubleSpinBox2(); tool->setText("..."); layout->addWidget(editor); layout->addWidget(tool); return w;
Dear spirit
In this way, tool button located in the spin not near
can show a screenshot?
in the attach
this may work
code updated.Code:
... w->setFocusProxy(sp); hbl->setMargin(0); hbl->setSpacing(0); hbl->addWidget(sp); hbl->addWidget(tb); return w; ... void ItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_UNUSED(index); editor->setGeometry(option.rect); }
this works great but we have a problem with
Code:
{ MyDoubleSpinBox2 *spinBox = static_cast<MyDoubleSpinBox2*>(w); spinBox->setValue(turkish.toDouble(index.model()->data(index, Qt::EditRole).toString().remove(totalParaBirimi, Qt::CaseInsensitive))); spinBox->selectAll(); }
Can we do it like this?
no, you can't do this. create your own widget which will return data.
himmmm
how can I do it then?
the simpliest way
nothing complex, right? ;)Code:
{ Q_OBJECT public: { setFocusProxy(m_spinBox); hbl->setMargin(0); hbl->setSpacing(0); hbl->addWidget(m_spinBox); hbl->addWidget(m_toolButton); } private: QSpinBox *m_spinBox; QToolButton *m_toolButton; }; ... void MyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { return new MyComplexEditor(parent); } { MyComplexEditor *mce = qobject_cast<MyComplexEditor *>(editor); if (!mce) return; mce->spinBox()->setValue(turkish.toDouble(index.model()->data(index, Qt::EditRole).toString().remove(totalParaBirimi, Qt::CaseInsensitive))); mce->spinBox()->selectAll(); } }
Thank you very much problem solved, but was not complex:)
I got one more question for the tool botton
I create a action, and add to toolbotton.
Code:
connect(enDusukAlis, SIGNAL(activated()), w->toolButton(), SLOT(slotenDusukAlis())); w->toolButton()->addAction(enDusukAlis);
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?
looks strange
QToolButton has not such slot slotenDusukAlis.Code:
connect(enDusukAlis, SIGNAL(activated()), w->toolButton(), SLOT(slotenDusukAlis()));
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?
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.