Results 1 to 5 of 5

Thread: qlayout and setGeometry

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Question qlayout and setGeometry

    Hi, I can't set dimension of vlay0 (or wid0) how my own; I'd like set its width such as the width of a checkBox; I tried every setGeometry but seems don't work. Why?
    Qt Code:
    1. QGroupBox* box = new QGroupBox (myFrame);
    2. box->setGeometry(5,5,myFrame->width()-10, myFrame->height()-10);
    3. box->setTitle("title");
    4. QWidget* wid = new QWidget(box);
    5. QWidget* wid0 = new QWidget(wid);
    6. wid->setGeometry(QRect (20,20,100,50));
    7. wid->setBackgroundColor(QColor (10,100,50));
    8.  
    9. wid0->setGeometry(QRect (0,0,5,20));
    10. QBoxLayout* hlay = new QHBoxLayout (wid);
    11. QCheckBox* c0 = new QCheckBox(wid0);
    12. c0->setBackgroundColor(QColor (10,100,50));
    13. QVBoxLayout* vlay0 = new QVBoxLayout (wid0);
    14. QLabel* l0 = new QLabel (wid0);
    15. l0->setText("l0");
    16. l0->setBackgroundColor(QColor (100,1,150));
    17. vlay0->addWidget(c0);
    18. vlay0->addWidget(l0);
    19. hlay->addWidget(wid0);
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qlayout and setGeometry

    You can't use setGeometry() when using layouts -- it'll simply not work. If you want to manipulate sizes of laid out widgets, you have to use sizeHint, sizePolicies and minimumSize and maximumSize properties.

    And remember to set a layout for that group box. It doesn't have one and maybe if you set it, all other widgets will stretch accordingly.

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: qlayout and setGeometry

    ok for before. but for example: how I can set the square of check in the middle
    of purple? Thaks; it seems not possible...
    Qt Code:
    1. QWidget* wid = new QWidget(box);
    2. QCheckBox* c4 = new QCheckBox(wid);
    3. c4->setGeometry(80,5,50,40);
    4. c4->setBackgroundColor(QColor(100, 0,255));
    To copy to clipboard, switch view to plain text mode 

    -----
    Also I can't change the width of purple...and now I don't use layout (only this code)
    Attached Images Attached Images
    Last edited by mickey; 2nd April 2006 at 12:50.
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qlayout and setGeometry

    Maybe it would be easier to subclass QButton and provide a custom paintEvent for it? One that would use QStyle::drawControl() and QStyle::drawPrimitive() with CE_CheckBox and PE_CheckMark respectively.

  5. #5
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: qlayout and setGeometry

    Beyond the setGeometry problem, how you can see in first attach, checkBox and QLabel named 'l0' aren't verticallly aligned; Why this? I use QVboxLayout but the align isn't perfect
    Thanks
    Regards

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.