比如用QLabel在主界面上画两条虚线:
bool ContentWidget::eventFilter(QObject *obj, QEvent *event) { if(obj == line_label_1 || obj == line_label_2) { if(event->type() == QEvent::Paint) { int label_height_1 = line_label_1->height(); int label_width_1 = line_label_1->width(); QPainter painter(line_label_1); painter.setPen(QPen(QColor(220, 220, 220), 1, Qt::DashLine)); painter.drawLine(label_width_1/2, 0, label_width_1/2, label_height_1); int label_height_2 = line_label_2->height(); int label_width_2 = line_label_2->width(); QPainter painter2(line_label_2); painter2.setPen(QPen(QColor(220, 220, 220), 1, Qt::DashLine)); painter2.drawLine(label_width_2/2, 0, label_width_2/2, label_height_2); } } return QWidget::eventFilter(obj, event); }
http://blog.sina.com.cn/s/blog_a6fb6cc90101e8lv.html