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. Clip drawing inside a frame
QtWS25 Last Chance

Clip drawing inside a frame

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.8k 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.
  • T Offline
    T Offline
    tony
    wrote on last edited by
    #1

    Hi,

    I'm trying to find a solution to my problem since days, without success :(

    What I need is to fill a frame with a color, drawn with QStyle classes. I have a widget, and I paint it in this way:

    @
    QStyleOptionFrameV3 opt;
    opt.initFrom(this);

    QStylePainter painter(this);
    painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);

    QRect frameRect(this->rect());

    opt.rect = frameRect;
    opt.state = QStyle::State_Sunken;
    opt.lineWidth = 1;
    opt.midLineWidth = 1;
    opt.frameShape = QFrame::StyledPanel;

    this->style()->drawControl(QStyle::CE_ShapedFrame,&opt,&painter,this);
    @

    Now I need to draw a filled rect (with some transparency), that is a percentage of the full frame rect (just like a progressbar). The problem is that the filled rect "overflows" the frame, painting outside too.
    Progressbar doesn't fit my needs, cause the filled color is changing according to some policies, as long as the value changes.

    I could adjust the filled rect, but I still have problems with the rounded corners.

    Is there a way to clip the drawing inside the "shape" of the styled frame?? I tried to look for a QStyle method, but I wasn't able to get the real shape of the frame.

    Another solution could be:

    a) paint the filled rect
    b) paint the rounded frame

    The point is that (b) doesn't clear the area outside the frame, so (a) remains even there. This is the way I've implemented it now.

    Can you help me finding out a good solution for my need?

    Thanks a lot!
    Tony.

    P.S.: Surprisingly, it seems to work fine when built for Windows, but I cannot explain why.

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      QPainter class has some "clipping":http://qt-project.org/doc/qt-4.8/qpainter.html#clipping capabilities.

      What type of QStyle has your widget? You could step into QStyle::drawControl() and check where the issue is.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      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