Qt 5.8.0。 MinGW 32位。 我需要在屏幕上绘制不同形状的对象。我使用OpenGL来加速和绘制不同的形状,但我还需要绘制QPaint。 我尝试用Qpainter(drawText函数)绘制Rect。屏幕上显示文字,但屏幕上没有显示。
实施例
如何使用QPainter绘制矩形,而不是使用OpenGL?我想绘制3个形状:使用OpenGL的三角形和矩形,使用QPainter的矩形。我的应用程序应绘制任何形状(使用QPainter),有时使用OpenGL加速绘制粒子。如何在一个小部件中组合它?
DrawingWidget.cpp的一部分:
public function scopeGetQuestion($query)
{
return $query->join('question_chapter_rel', 'chapters.id', '=' ,'question_chapter_rel.chapter_id')
->join('questions','questions.id', '=' ,'question_chapter_rel.question_id')
->join('answers','answers.id', '=' ,'questions.correct_answers')
->select(
[
'chapters.id',
'chapters.chapter_description',
'questions.id',
'questions.question_description',
'answers.id',
'answers.answer_description'
]
)
->where('answers.is_correct',1)
->paginate(12);
}
主:
select `chapters`.`id`, `chapters`.`chapter_description`, `questions`.`id`, `questions`.`question_description`, `answers`.`id`, `answers`.`answer_description`
from `chapters`
Inner Join `question_chapter_rel`
on `chapters`.`id` = `question_chapter_rel`.`chapter_id`
Inner Join `questions`
on `questions`.`id` = `question_chapter_rel`.`question_id`
Inner Join `answers`
on `answers`.`id` = `questions`.`correct_answers`
where `answers`.`is_correct` = 1
17年4月18日
ahaha,所以,当我在绘制文本应用程序工作后绘制到rect时,如果我尝试在rect后绘制文本或尝试绘制rect而不使用文本,则无效
void DrawingWidget::paintGL()
{
m_painter = new QPainter(this);
m_painter->beginNativePainting();
m_program->bind();
m_modelView.setToIdentity();
m_modelView.translate(-1.5f, 0.0f, -6.0f);
m_program->setUniformValue("mvpMatrix", m_projection * m_modelView);
glBindBuffer(GL_ARRAY_BUFFER, m_vboIds[0]);
m_program->enableAttributeArray(m_posAttr);
m_program->setAttributeBuffer(m_posAttr, GL_FLOAT, 0, 3);
glBindBuffer(GL_ARRAY_BUFFER, m_vboIds[1]);
m_program->enableAttributeArray(m_colAttr);
m_program->setAttributeBuffer(m_colAttr, GL_FLOAT, 0, 3);
glDrawArrays(GL_TRIANGLES, 0, 3);
m_modelView.translate(3.0f, 0.0f, 0.0f);
m_program->setUniformValue("mvpMatrix", m_projection * m_modelView);
glBindBuffer(GL_ARRAY_BUFFER, m_vboIds[2]);
m_program->enableAttributeArray(m_posAttr);
m_program->setAttributeBuffer(m_posAttr, GL_FLOAT, 0, 3);
glBindBuffer(GL_ARRAY_BUFFER, m_vboIds[3]);
m_program->enableAttributeArray(m_colAttr);
m_program->setAttributeBuffer(m_colAttr, GL_FLOAT, 0, 3);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
m_program->release();
m_painter->endNativePainting();
drawText();
m_painter->end();
}
void DrawingWidget::drawText()
{
m_painter->setPen(QColor(Qt::green));
m_painter->setBrush(QBrush(QColor(Qt::red)));
m_painter->drawRect(QRect(QPoint(10, 10), QPoint(50, 44)));
m_painter->drawText(0, 40, QString("TEST"));
}