Results 1 to 6 of 6

Thread: Custom QFrame

  1. #1
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Custom QFrame

    Hi,
    I want create a new widget like a QFrame but with a customized frame, something like this one:


    My idea is to inherit from QWidget, insert a QFrame in its vertical layout and overide the QWidget:rintEvent and draw my custom frame around the QFrame but I've some problems with the the right size of the QFrame.
    Is there a better way to do my task?

    Obsviously, than I want to be enabled to insert other widgets inside the white space like in a standard QFrame...

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Custom QFrame

    Why not derive QFrame it self?
    It is of course possible the way you are doing it too.
    But other then that, that is the way to go, yes.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Custom QFrame

    Quote Originally Posted by high_flyer View Post
    Why not derive QFrame it self?
    It is of course possible the way you are doing it too.
    But other then that, that is the way to go, yes.
    Ok...but if I directly inherit from QFrame than how I can customize the frame border?

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Custom QFrame

    The same way you where doing it with subclassing QWidget - by overloading the paintEvent().
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Custom QFrame

    Quote Originally Posted by high_flyer View Post
    The same way you where doing it with subclassing QWidget - by overloading the paintEvent().
    ok I supose that but...in the paintEvent, how can I draw around the contents view? What is the right bounding of the contents? I try to use the contentsRect but then drawing is not so fine...later I try to post a portion of code.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Custom QFrame

    look at QWidget::setContentsMargins ( )
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 12
    Last Post: 5th July 2009, 16:03
  2. Replies: 2
    Last Post: 16th May 2008, 14:39
  3. Custom widget
    By zorro68 in forum Qt Programming
    Replies: 7
    Last Post: 28th January 2008, 14:06
  4. custom plug-in widget in another custom plug-in widget.
    By MrGarbage in forum Qt Programming
    Replies: 6
    Last Post: 27th August 2007, 15:38
  5. QFrame subclass does not reparent
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 21st March 2006, 22:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.