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]How to calculate the border-width of a widget in the paintEvent?
QtWS25 Last Chance

[Solved]How to calculate the border-width of a widget in the paintEvent?

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

    I have a custom widget for which i have specified the stylesheet as

    @setStyleSheet("border: 5px solid red");@

    which can also be specified in a qss file like

    @#MyWidget
    {
    border: 10px solid red;
    }@

    Since its a QWidget so to make the styleSheet work i added in the paintEvent() fuction of MyWidget

    @void MyWidget::paintEvent(QPaintEvent *e)
    {
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
    }@

    The above code has the following output

    !http://img825.imageshack.us/img825/4130/capturesug.png(image)!
    How can I calculate/get the border-width in the paintEvent() if the border is specified using stylesheet;

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on last edited by
      #2

      After working on this for few hrs i figured out that QWidget does not provide any information about the border-width. So instead of using QWidget i use QFrame.

      My requirement was to paint in the available area excluding the border for a widget.

      This is achieved by using QFrame that provide "frameWidth()":http://doc.qt.nokia.com/4.7-snapshot/qframe.html#frameWidth-prop and "contentsRect()":http:// for the same purpose.

      Thanks.

      1 Reply Last reply
      1

      • Login

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