Reputation: 11
I am trying to auto click and refresh 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());
}
Upvotes: 1
Views: 712
Reputation: 73041
Once you have a pointer to your QPushButton, you can call click() on it; 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.
Upvotes: 2
Reputation: 48258
a slot is nothing else as a method, you can call it in the same MainWindows class and it will do the same logic as you were clicking the button
Upvotes: 0