Results 1 to 6 of 6

Thread: What is a Qframe? can I use it as a layout/container?

  1. #1
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default What is a Qframe? can I use it as a layout/container?

    In the Designer, I can create/drag a Qframe onto the canvas, then add items inside. To me this feels like a container/layout object. Any truth to that? Can I use Qframe as I would a Layout?
    I did check out the docs, and that says I should treat Qframe like a styling element and not a layout element. So I'm a bit confused.

    I did compile the UI from the designer to see the code, and it wasn't helpful. The code doesn't reflect a "layout style" workflow, meaning it doesn't add items via a ".setLayout" or "addItems" equivalent.

    I've added a quick pic of what I have in the designer. I'm trying to write that via Python to get the exact same result. (via code alone)

    I have 3 labels. One is a pixmap. How do I add those to to the frame to get what I did in the designer?

    Thanks!

    20160627_200116.jpg

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: What is a Qframe? can I use it as a layout/container?

    QFrame is most often used as a container, i.e. other widgets are add as its children and then layouted within its boundaries.

    It can be used as just a visual item, e.g. as a separator line.

    As for your screenshot: if you look at the object tree you will see that both container widgets (the main form itself and the frame) have the "missing layout" indicator item.

    Which is why your generated code did not have any layout related calls, there aren't any in there yet.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What is a Qframe? can I use it as a layout/container?

    Thanks Anda.
    I used .setLayout() member on the Qframe object, which seems to work fine, but you mentioned adding widgets as a child to the Qframe. Which class member would I use to add child?

    Although I did get it working and was able to replicate what I have in the designer, I feel that it's the incorrect way as it's not done the same way as the auto generate code does it. I still don't understand how the designer generated code gets the result it gets.
    The generated code creates a Qframe object, and adds it to the Qlabel object as an argument....that's it! and it all works. I don't see how it connected, or how it sets the position. :/

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: What is a Qframe? can I use it as a layout/container?

    Quote Originally Posted by Nfrancisj View Post
    I used .setLayout() member on the Qframe object, which seems to work fine, but you mentioned adding widgets as a child to the Qframe. Which class member would I use to add child?
    When you are using a layout, then you don't have to care about this. The layout will ensure the correct parent/child relationship between the frame and the elements in its layout.

    Quote Originally Posted by Nfrancisj View Post
    Although I did get it working and was able to replicate what I have in the designer, I feel that it's the incorrect way as it's not done the same way as the auto generate code does it.
    Sounds good to me, but you can show your code if you'd like someone to have a look.

    Quote Originally Posted by Nfrancisj View Post
    I still don't understand how the designer generated code gets the result it gets.
    Your designer scene was missing the layouts, so uic couldn't generate any code for that.

    Quote Originally Posted by Nfrancisj View Post
    The generated code creates a Qframe object, and adds it to the Qlabel object as an argument....that's it! and it all works.
    It passes the frame (container) as the parent to the widgets that are inside the container.

    Quote Originally Posted by Nfrancisj View Post
    I don't see how it connected, or how it sets the position. :/
    Since there is no layout very likely by calling setGeometry() on each child.

    Cheers,
    _

  5. #5
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What is a Qframe? can I use it as a layout/container?

    thanks! makes sense.

    Diving deeper into Qframe, is there a way to give it mouse clicked events like a push button?
    i used the Qframe to make thumbnails, but now i need click and context menu actions. :?

    thanks

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: What is a Qframe? can I use it as a layout/container?

    Quote Originally Posted by Nfrancisj View Post
    Diving deeper into Qframe, is there a way to give it mouse clicked events like a push button?
    Yes, you just need to overwrite the mouse event handler functions that you need, e.g. QWidget::mousePressEvent().

    Quote Originally Posted by Nfrancisj View Post
    i used the Qframe to make thumbnails, but now i need click and context menu actions. :?
    For context menu there are several options.
    The easiest way is to add actions to the widget, see QWidget::addAction().

    Cheers,
    _

Similar Threads

  1. Replies: 6
    Last Post: 16th December 2015, 11:55
  2. Apply Layout to custom widget plugin container
    By Alex87 in forum Qt Programming
    Replies: 7
    Last Post: 28th July 2014, 13:57
  3. Control spacing of a QFrame layout using a Stylesheet
    By gmat4321 in forum Qt Programming
    Replies: 1
    Last Post: 21st October 2012, 19:18
  4. How to fill a QFrame space in QSplitter layout
    By henryjoye in forum Qt Programming
    Replies: 2
    Last Post: 12th October 2010, 05:18
  5. Quick ? about qSort(Container & container)
    By JimDaniel in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2007, 11:20

Tags for this Thread

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.