I want to know the way that we can use an id button from a window to another.
For example I want to get a text from a window dialog that I create after clicking on ok button?
I've tried a signal that get the id button from a groupbutton, I've tried also to create a boolean variable that takes true
when the ok button is clicked but nothing works.
bool Dialog2::getIdok()
{
//qDebug() << "c'est id" << gb->id(b1) << "qui a été cliqué";
if(gb->id(b1))
return true;
}
the arrow.cpp paint event which contains the drawtext that i want to change:
void Arrow::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget *)
{
if (myStartItem->collidesWithItem(myEndItem))
return;
QPen myPen = pen();
myPen.setColor(myColor);
qreal arrowSize = 20;
painter->setPen(myPen);
painter->setBrush(myColor);
QLineF centerLine(myStartItem->pos(), myEndItem->pos());
QPolygonF endPolygon = myEndItem->polygon();
QPointF p1 = endPolygon.first() + myEndItem->pos();
QPointF p2;
QPointF intersectPoint;
QLineF polyLine;
for (int i = 1; i < endPolygon.count(); ++i)
{
p2 = endPolygon.at(i) + myEndItem->pos();
polyLine = QLineF(p1, p2);
QLineF::IntersectType intersectType = polyLine.intersect(centerLine, &intersectPoint);
if (intersectType == QLineF::BoundedIntersection)
break;
p1 = p2;
}
setLine(QLineF(intersectPoint, myStartItem->pos()));
double angle = ::acos(line().dx() / line().length());
if (line().dy() >= 0)
angle = (Pi * 2) - angle;
QPointF arrowP1 = line().p1() +
QPointF( sin( angle + Pi / 3 ) * arrowSize,
cos( angle + Pi / 3 ) * arrowSize );
QPointF arrowP2 = line().p1() +
QPointF( sin( angle + Pi - Pi / 3 ) * arrowSize,
cos( angle + Pi - Pi / 3 ) * arrowSize);
QPolygonF startPolygon = myStartItem->polygon();
QPointF p3 = startPolygon.first() +
myStartItem->pos() -
QPointF( sin( angle + Pi / 2 ) * arrowSize,
cos( angle + Pi / 2 ) * arrowSize );
arrowHead.clear();
arrowHead << line().p1() << arrowP1 << arrowP2;
painter->drawLine(line());
painter->drawText(p3,m1);
painter->drawText( arrowP2,m2);
if (isSelected())
{
painter->setPen(QPen(myColor, 1, Qt::DashLine));
QLineF myLine = line();
myLine.translate(0, 4.0);
painter->drawLine(myLine);
myLine.translate(0,-8.0);
painter->drawLine(myLine);
}
}
And i have created a dialog class which contains an int variable that take 1 when i click on ok button,and in arrow class when i double clik the dialog shows up but when i click ok button nothing happen.Here is the doubleclickmouse event method:
void Arrow::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
if (mouseEvent->button() != Qt::LeftButton)
return;
mydiag = new Dialog2();
mydiag->show();
if(mydiag->cc==1)
{
m1 = mydiag->getvalue1();
m2 = mydiag->getvalue2();
}
}
答案 0 :(得分:0)
创建自定义对话框时,您可以填写QComboBox
,当您关闭对话框时,您可以从中读取数据。
例如,您可以使用对话框标题:
class YourDialog : public QDialog
{
// ...
void setItems( const QStringList& aItems );
QString item() const;
// ...
};
在您的源文件中:
YourDialog::setItems( const QStringList& aItems )
{
ui->ComboBox->addItems( aItems );
}
QString YourDialog::item() const
{
return ui->ComboBox->currentText();
}
你可以像这样使用它:
QStringList list;
list << "dog" << "pig";
YourDialog dialog;
dialog.setItems( list );
if ( dialog.exec() == QDialog::Accepted )
{
const QString selectedItem = dialog.item();
}