Results 1 to 10 of 10

Thread: How to set the base widget when subclassing Qt widget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2014
    Posts
    136
    Qt products
    Qt3 Qt4 PyQt3 PyQt4
    Platforms
    MacOS X Windows
    Thanks
    72

    Default Re: How to set the base widget when subclassing Qt widget

    Quote Originally Posted by Lesiok View Post
    As I see class MyWidget is inherited from QFrame. So for what is QFrame *baseWidget ?
    Yes, that is the problem you see. I want this to be baseWidget. So that the parent of this (or baseWidget) is the parent widget I pass in as parameter. How do I do it?

    Quote Originally Posted by ChrisW67 View Post
    BaseWidget is positioned in the top left because you gave it the MyWidget instance as a parent and, I am guessing, did not put it in a layout applied to the MyWidget instance. What is the function of baseWidget? Have you put other widgets inside it instead of inside the MyWidget container? It certainly sounds like that from your questions.
    Yes, baseWidget will have lots of sub-widgets in it. I pass in the parent because it has to be positioned at a particular position in the parent widget, layout agnostic. If I do

    Qt Code:
    1. QFrame *baseWidget = new QFrame(this);
    2. baseWidget->setGeometry(x,y,width,height);
    3. //add more widgets to baseWidget
    To copy to clipboard, switch view to plain text mode 

    in the parent widget code, it works fine. I want to do the same things, except baseWidget will be of type MyWidget that inherits from QFrame.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: How to set the base widget when subclassing Qt widget

    Are you sure you know what is the classe inheritance ?
    Class MyWidget is QFrame too. You do not need field baseWidget and extra WFrame object.

  3. #3
    Join Date
    May 2014
    Posts
    136
    Qt products
    Qt3 Qt4 PyQt3 PyQt4
    Platforms
    MacOS X Windows
    Thanks
    72

    Default Re: How to set the base widget when subclassing Qt widget

    Yes, I know that. I tried this as well:

    Qt Code:
    1. this->setStyleSheet("background: rgb(246,247,239); border-radius: 5px;");
    2. this->setParent(parent);
    3. this->show();
    To copy to clipboard, switch view to plain text mode 

    instead of creating a new QFrame baseWidget. Doesn't work. Doesn't show up at all, unlike the last one where it showed up but not taking the geometry correctly.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: How to set the base widget when subclassing Qt widget

    Construct MYWidget so that the content you put in baseWidget is its content, and throw away baseWidget, then you will get what you are expecting.

Similar Threads

  1. Replies: 0
    Last Post: 3rd August 2011, 13:07
  2. How to get the base parent Widget
    By vaibhav in forum Qt Programming
    Replies: 8
    Last Post: 15th February 2011, 12:27
  3. Subclassing a widget created in Qt Designer
    By dmginc in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2011, 07:30
  4. MVC - Abstract Widget Base Class - setupUI
    By SenSej in forum Newbie
    Replies: 0
    Last Post: 13th October 2008, 11:44
  5. Replies: 2
    Last Post: 14th February 2008, 21:06

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
  •  
Qt is a trademark of The Qt Company.