Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to change the position of DrawLine according to the size of the widget



  • void wCtrl_Indicator::drawTicks(QPainter* painter)
    {
    	QBrush		brushActive(QColor(58,62,64));
    	QPen		pen(QBrush(brushActive), 2);
    	pen.setCapStyle(Qt::FlatCap);
    	painter->setPen(pen);
    
    	QPoint c = this->rect().center();
    	painter->translate(c);
    	painter->rotate(-90);
    
    	for (int s = 0; s <= THICKS_STEP; s++)
    	{
    		painter->drawLine(15, 0, 25, 0);
    		painter->rotate(360 / THICKS_STEP);
    	}
    }
    
    void wCtrl_Indicator::drawBackGround(QPainter* painter)
    {
    	QPoint	center = this->rect().center();
    	QRect	drawingRect(
    		center.x()-20 , 
    		center.y()-20 , 
    		this->size().height() * 50 / 100,
    		this->size().height() * 50 / 100);
    
    	QBrush	brushBackgnd(QColor(82, 95, 99));
    	QPen	pen(QBrush(brushBackgnd), PROGRESS_THINKNESS);
    	pen.setCapStyle(Qt::FlatCap);
    
    	painter->setPen(pen);
    	painter->setBrush(brushBackgnd);
    	painter->drawArc(drawingRect, 90 * 16, ConvertAngle(m_nMax) * 16);
    }
    
    void wCtrl_Indicator::drawProgress(QPainter* painter)
    {
    	QPoint	center = this->rect().center();
    	QRect	drawingRect(
    		center.x() - 20,
    		center.y() - 20,
    		this->size().height() * 50 / 100,
    		this->size().height() * 50 / 100);
    
    	QBrush	brushBackgnd(QColor(75, 147, 191));
    	QPen	pen(QBrush(brushBackgnd), PROGRESS_THINKNESS);
    	pen.setCapStyle(Qt::FlatCap);
    
    	painter->setPen(pen);
    	painter->setBrush(brushBackgnd);
    	painter->drawArc(drawingRect, (m_dTransAngle--)* 16, 45 * 16);
    }
    

    268d63ac-a28f-4f57-8c70-f6da64817651-image.png

    I made this widget, but if I change the size of the drawarc, the drawline should also be changed to match the size of the drawarc, but that's not possible.
    Is there a way to automatically calculate the size?

    cae6ec83-df99-41df-a914-a31967ee2e32-image.png


Log in to reply