Drawing a line on a QWidget

不打扰是莪最后的温柔 提交于 2019-11-30 18:49:10

The simplest way to create a horizontal line in Qt is to use a QFrame with the frameShape property set to QFrame::HLine. You can then place this frame in your grid layout with the appropriate column span. Here's a simple, contrived example:

QFrame* myFrame = new QFrame();
myFrame->setFrameShape(QFrame::HLine);

const int NUMBER_OF_COLUMNS_IN_GRID = 4;
myGridLayout->addWidget(myFrame, 0, 0, 1, NUMBER_OF_COLUMNS_IN_GRID);

This should do everything you need it do to, including automatically resize when the parent layout resizes. You can also play with the frame's palette to show it in the desired color.

You misspelled QPaintEvent. The mispelling means that your paintEvent() function does not override the base classes' paintEvent().

Because you never use the variable e of "QPainEvent", there is no syntax error.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!