#include "mainwindow.h" #include "uimainwindow.h" #include <QFileDialog> #include…
- User
#include "mainwindow.h" #include "ui_mainwindow.h" #include #include #include #include #include #include
MainWindow::MainWindow(QWidget parent) : QMainWindow(parent) { // Set window title setWindowTitle("Abdugaffor L. - IVT1 B-22 - QT-GI-15");
// Create label for image pic_ = new QLabel(this);
// Create animation for image animation_ = new QPropertyAnimation(pic_, "pos", this); animation_->setDuration(2000); animation_->setStartValue(QPoint(0, 0)); animation_->setEndValue(QPoint(200, 200)); animation_->setLoopCount(-1);
// Create and add menu createMenu();
// Set central widget as label for image setCentralWidget(pic_); }
MainWindow::~MainWindow() { }
void MainWindow::createMenu() { // Create menu bar QMenuBar *menubar = menuBar();
// Create “File” menu file_ = menubar->addMenu("File");
// Create menu actions show_pic_ = new QAction("Show picture", this); choose_pic_ = new QAction("Choose", this); animate_ = new QAction("Animate", this); stop_ = new QAction("Stop", this); quit_ = new QAction("Quit", this);
// Add actions to “File” menu file_->addAction(show_pic_); file_->addAction(choose_pic_); file_->addSeparator(); file_->addAction(animate_); file_->addAction(stop_); file_->addSeparator(); file_->addAction(quit_);
// Connect signals and slots connect(show_pic_, SIGNAL(triggered()), this, SLOT(showPicture())); connect(choose_pic_, SIGNAL(triggered()), this, SLOT(chooseImage())); connect(animate_, SIGNAL(triggered()), this, SLOT(animateImage())); connect(stop_, SIGNAL(triggered()), this, SLOT(stopAnimation())); connect(quit_, SIGNAL(triggered()), qApp, SLOT(quit())); }
void MainWindow::showPicture() {
// Create image QImage image(300, 300, QImage::Format_ARGB32_Premultiplied); image.fill(Qt::white);
// Draw rectangle QPainter painter(&image); painter.setBrush(Qt::blue); painter.drawRect(50, 50, 200, 100);
// Draw triangle QPolygonF triangle; triangle.append(QPointF(150, 150)); triangle.append(QPointF(100, 250)); triangle.append(QPointF(200, 250)); painter.setBrush(Qt::red); painter.drawPolygon(triangle);
// Draw circle painter.setBrush(Qt::green); painter.drawEllipse(QRectF(100, 100, 100, 100));
// Draw trapezoid QPolygonF trapezoid; trapezoid.append(QPointF(100, 200)); trapezoid.append(QPointF(130, 250)); trapezoid.append(QPointF(170, 250)); trapezoid.append(QPointF(200, 200)); painter.setBrush(Qt::yellow); painter.drawPolygon(trapezoid);
// Show image pic_->setPixmap(QPixmap::fromImage(image));
}
void MainWindow::chooseImage() { // Open file dialog for image selection QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), "", tr("Image Files (.png .jpg .bmp)"));
// If a file was selected, set it as the image source if (!fileName.isEmpty()) { QPixmap image(fileName); pic_->setPixmap(image);
- Assistant
The error indicates that there is no declaration that matches the constructor function
MainWindow::MainWindow(QWidget parent).One possible reason for this error could be a mismatch between the definition and declaration of the constructor function. Make sure that the declaration in the header file (
mainwindow.h) matches the definition in the source file (mainwindow.cpp).Also, make sure that the constructor is declared as
publicin the header file. - User
void MainWindow::chooseImage() { // Open file dialog for image selection //QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), "", tr("Image Files (.png .jpg .bmp)"));
// If a file was selected, set it as the image source //if (!fileName.isEmpty()) { //QPixmap image(fileName); //pic_->setPixmap(image);
// Create a dialog for speed and direction selection QDialog *dialog = new QDialog(this); QVBoxLayout *layout = new QVBoxLayout(dialog);
// Add a text box for speed input int speed = QInputDialog::getInt(this, tr("Set Speed"), tr("Speed:"), 1, 1);
// Add radio buttons for direction selection QGroupBox groupbox = new QGroupBox(tr("Direction"), dialog); QRadioButton radio_up_down = new QRadioButton(tr("Up-Down"), groupbox); QRadioButton* radio_left_right = new QRadioButton(tr("Left-Right"), groupbox); QHBoxLayout* hlayout = new QHBoxLayout(groupbox); hlayout->addWidget(radio_up_down); hlayout->addWidget(radio_left_right); groupbox->setLayout(hlayout); layout->addWidget(groupbox);
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.