Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to change the position of DrawLine according to the size of the widget
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 368 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    IknowQT
    wrote on last edited by
    #1
    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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved