예제 #1
0
void NumberWidget::onNumberButtonClicked(bool checked)
{
    // Downcast. Any other good idea?
    QAbstractButton * btn = static_cast<QAbstractButton *>(sender());
    bool ok = false;
    int number = btn->text().toInt(&ok);

    // Handle overflow.
    if (ok)
    {
        emit numberClicked( number );
    }
}
예제 #2
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    for (int i=0;i<9;++i)
        for(int j=0;j<9;++j)
        {
            square[i][j] = new QPushButton("",this);
            connect(square[i][j],SIGNAL(released()),this,SLOT(squareClicked()));
        }

    for (int i=0;i<9;++i)
    {
        number[i]=new QPushButton(QString::number(i+1),this);
        connect(number[i],SIGNAL(released()),this,SLOT(numberClicked()));
    }

    emtyButton = new QPushButton("Emty",this);
    emtyButton->setGeometry(QRect(QPoint(25,460),QSize(150,40)));
    connect(emtyButton,SIGNAL(released()),this,SLOT(emtyClicked()));

    solveButton = new QPushButton("Solve",this);
    solveButton->setGeometry(QRect(QPoint(200,340),QSize(115,67)));
    connect(solveButton,SIGNAL(released()),this,SLOT(solveClicked()));

    clearButton = new QPushButton("Clear",this);
    clearButton->setGeometry(QRect(QPoint(200,433),QSize(115,67)));
    connect(clearButton,SIGNAL(released()),this,SLOT(clearClicked()));

    redText = new QPalette();
    redText->setColor(QPalette::ButtonText,Qt::red);

    blueText = new QPalette();
    blueText->setColor(QPalette::ButtonText,Qt::blue);

    blackText = new QPalette();
    blackText->setColor(QPalette::ButtonText,Qt::black);

    setSquareGeo();
    setNumberGeo();
}