Results 1 to 5 of 5

Thread: QVBoxLayout whats wrong in this

  1. #1
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default QVBoxLayout whats wrong in this

    #include <QApplication>
    #include <QWidget>
    #include <QPushButton>
    #include <QVBoxLayout>
    #include <QPalette>
    int main(int argc, char **argv)
    {
    QApplication app(argc,argv);
    QWidget *widget = new QWidget;
    widget->resize(500,300);

    QPalette r(widget->palette());
    r.setColor(QPalette::Background, Qt::red);
    widget->setPalette(r);


    QWidget *w1 = new QWidget(widget);
    w1->resize(300,150);
    QPalette p(w1->palette());
    p.setColor(QPalette::Background, Qt::green);
    w1->setPalette(p);

    QWidget *w2 = new QWidget(widget);
    w2->resize(300,150);
    QPalette q(w2->palette());
    q.setColor(QPalette::Background, Qt::blue);
    w2->setPalette(q);

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(w1);
    layout->addWidget(w2);

    widget->setLayout(layout);

    widget->show();

    return app.exec();
    }

    I am not able to see the distinguished two colored widgets.

  2. #2
    Join Date
    May 2010
    Posts
    61
    Thanks
    2
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QVBoxLayout whats wrong in this

    Hi sujan.dasmahapatra,

    QWidget objects act as a container, and since your child widgets (w1 and w2) do not contain anything, they are not visible.
    Try putting some objects into them.

    Wladek.
    One second is long, everything longer than two seconds is definitely too long.

  3. #3
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QVBoxLayout whats wrong in this

    The palette is propagated from parent to child, so all your widgets will get red background, read more here

  4. #4
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QVBoxLayout whats wrong in this

    hi,
    I am not able to see the distinguished two colored widgets.
    you can try stylesheet
    Qt Code:
    1. widget->setStyleSheet("background-color:red;");
    2. w1->setStyleSheet("background-color:green;");
    3. w2->setStyleSheet("background-color:blue;");
    To copy to clipboard, switch view to plain text mode 

    hope it helps,
    Bala

  5. #5
    Join Date
    May 2010
    Posts
    61
    Thanks
    2
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QVBoxLayout whats wrong in this

    I would like to apologize for my reply, was a little "off targeted".
    One second is long, everything longer than two seconds is definitely too long.

Similar Threads

  1. Whats a manifest file for vc++
    By tgreaves in forum General Programming
    Replies: 4
    Last Post: 14th May 2012, 09:46
  2. Whats wrong with QList<QGraphicsItem>
    By rubenvb in forum Newbie
    Replies: 6
    Last Post: 22nd January 2010, 19:01
  3. Whats wrong with this script -- help needed
    By swamyonline in forum Qt Programming
    Replies: 5
    Last Post: 2nd July 2009, 13:17
  4. Whats This box too small
    By bruccutler in forum Qt Programming
    Replies: 5
    Last Post: 30th March 2007, 23:52
  5. Replies: 1
    Last Post: 18th March 2006, 16:37

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.