简体   繁体   English

如何在 QT 上自动点击 QPushButton

[英]How To Auto Click QPushButton on QT

I am trying to auto click and refresh QTextBrowser.我正在尝试自动单击并刷新 QTextBrowser。 But can't figure it out how.但想不通怎么办。 My codes are below.我的代码如下。

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QPixmap pix_w ("/home/pi/Downloads/wifi.png");
    QPixmap pix_s ("/home/pi/Downloads/laser.png");
    QPixmap pix_m ("/home/pi/Downloads/main.png");
    ui->label->setPixmap(pix_w);
    ui->label_2->setPixmap(pix_s);
    ui->label_5->setPixmap(pix_m);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    QFile file("/home/pi/Desktop/test1.txt");
        if(!file.open(QIODevice::ReadOnly))
            QMessageBox::information(0,"info",file.errorString());

        QTextStream in(&file);

        ui->textBrowser->setText(in.readAll());
}

Once you have a pointer to your QPushButton, you can call click() on it;一旦你有一个指向你的 QPushButton 的指针,你就可以在它上面调用click() or if you'd like to see the button visually animate, as if the user had clicked on it (in addition to emitting its clicked() signal), you can call animateClick() on it instead.或者,如果您希望看到按钮的视觉动画效果,就好像用户点击了它一样(除了发出clicked()信号),您可以在其上调用animateClick()

插槽不是其他方法,您可以在同一个 MainWindows 类中调用它,它会执行与单击按钮相同的逻辑

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM