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. [Solved]QSpinBox not drawn correctly
Servers for Qt installer are currently down

[Solved]QSpinBox not drawn correctly

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.8k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    cmannett85
    wrote on 9 Mar 2013, 21:45 last edited by
    #1

    I'm currently implementing a custom delegate, in part of which I need a QSpinBox to be drawn in the paint(..) method.

    @void Sy_floatingPointPD::paint( QPainter* painter,
    const QStyleOptionViewItem& option,
    const QModelIndex& index ) const
    {
    painter->save();

    //  Paint check box.
    QStyleOptionSpinBox spOpt;
    spOpt.palette     = option.palette;
    spOpt.rect        = option.rect;
    spOpt.state       = option.state;
    spOpt.frame       = true;
    spOpt.stepEnabled = QAbstractSpinBox::StepUpEnabled |
                       QAbstractSpinBox::StepDownEnabled;
    
    style->drawComplexControl( QStyle::CC_SpinBox, &spOpt, painter );
    
    painter->restore();
    

    }@

    Unfortunately it appears as:

    !http://i.stack.imgur.com/jMzaz.jpg(Error)!

    As you can see the step buttons are drawn massive and only the down arrow appears. Interestingly the width of the buttons mirrors that of the first table column, despite option.rect being the size of the cell (which is correct, which is presumably why the frame is drawn correctly).

    Any ideas what information I'm not giving QStyle?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jens
      wrote on 10 Mar 2013, 09:10 last edited by
      #2

      Some styles are written with the assumption that they get painted to the widget starting at (0,0) since that is the normal way widgets will paint them, but item views will assign an offset to the style rect.

      Perhaps you could try something like the following to trick the style into thinking it is drawing at the origin:
      @
      painter->save();
      painter->translate(option.rect.x(), option.rect.y());
      // Paint check box.
      QStyleOptionSpinBox spOpt;
      spOpt.palette = option.palette;
      spOpt.rect = QRect(0, 0, option.rect.width(), option.rect.height());
      spOpt.state = option.state;
      spOpt.frame = true;
      spOpt.stepEnabled = QAbstractSpinBox::StepUpEnabled |
      QAbstractSpinBox::StepDownEnabled;

      style->drawComplexControl( QStyle::CC_SpinBox, &spOpt, painter );
      
      painter->restore();
      

      @

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cmannett85
        wrote on 10 Mar 2013, 10:33 last edited by
        #3

        I have to say I didn't expect that to work as the frame and field subcomponents were in the right place and the right size - but I was thankfully proven wrong! Thank you.

        1 Reply Last reply
        0

        1/3

        9 Mar 2013, 21:45

        • Login

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