QT5联合halcon在控件显示字符
本次讲解QT5联合halcon时需要在控件上显示字符的问题;
QT5+halcon19.05。
.h文件加入如下代码:
//halcon 机器视觉软件自学交流:817798354
void disp_winodws(HTuple win,int width,int height,
int row,int col,QString color,QString text);
随后在.cpp中加入如下代码:
//halcon 机器视觉软件自学交流:817798354
void MainWindow::disp_winodws(HTuple win,int width,int height,
int row,int col,QString color,QString text)
{
SetPart(win, 0, 0, width,height);
SetColor(win,color.toStdString().c_str());
SetFont(win,"-fixed-32-");
SetTposition(win,row,col);
WriteString(win,text.toStdString().c_str());
}
随后调用该函数(需要将lable转成halcon窗口句柄)
//halcon 机器视觉软件自学交流:817798354
OpenWindow(0, 0, ui->label->width(), ui->label->height(),
(Hlong)this->ui->label->winId(), "visible", "", &hv_WindowHandle);
disp_winodws(hv_WindowHandle,ui->label->width(),
ui->label->height(),50,50,"red","this is string");
显示效果如下图所示: