Results 1 to 7 of 7

Thread: Why QGridLayout works wrong??

  1. #1
    Join Date
    Aug 2008
    Posts
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Why QGridLayout works wrong??

    I use QGridLayout to layout my widgets, I want to layout the widgets in 5 rows and 6 columns
    only the button of "%" and "_" take one column, the "获取属性值" button take 4 columns, all other widgets may take 2 columns, the fellowing is my code, howerer,It sames that the button "%" and "_" have take 2 columns. How to solve this probem? thank you!
    Qt Code:
    1. QGridLayout* CDlgAttributesQuery::createOperationBtns()
    2. {
    3. QPushButton* pBtn;
    4.  
    5. pBtn = new QPushButton("=");
    6. m_pBtnGroup->addButton(pBtn,btn_Operation_Equal_To);
    7. pG->addWidget(pBtn,0,0,1,2);
    8. pBtn = new QPushButton("<>");
    9. m_pBtnGroup->addButton(pBtn,btn_Operation_Not_Equal);
    10. pG->addWidget(pBtn,0,2,1,2);
    11. pBtn = new QPushButton("Like");
    12. m_pBtnGroup->addButton(pBtn,btn_Operation_Key_Like);
    13. pG->addWidget(pBtn,0,4,1,2);
    14.  
    15. pBtn = new QPushButton(">");
    16. m_pBtnGroup->addButton(pBtn,btn_Operation_Greater_Than);
    17. pG->addWidget(pBtn,1,0,1,2);
    18. pBtn = new QPushButton(">=");
    19. m_pBtnGroup->addButton(pBtn,btn_Operation_Greater_Equal);
    20. pG->addWidget(pBtn,1,2,1,2);
    21. pBtn = new QPushButton("And");
    22. m_pBtnGroup->addButton(pBtn,btn_Operation_Key_And);
    23. pG->addWidget(pBtn,1,4,1,2);
    24.  
    25. pBtn = new QPushButton("<");
    26. m_pBtnGroup->addButton(pBtn,btn_Operation_Smaller_Than);
    27. pG->addWidget(pBtn,2,0,1,2);
    28. pBtn = new QPushButton("<=");
    29. m_pBtnGroup->addButton(pBtn,btn_Operation_Smaller_Equal);
    30. pG->addWidget(pBtn,2,2,1,2);
    31. pBtn = new QPushButton("Or");
    32. m_pBtnGroup->addButton(pBtn,btn_Operation_Key_Or);
    33. pG->addWidget(pBtn,2,4,1,2);
    34.  
    35. pBtn = new QPushButton("%");
    36. m_pBtnGroup->addButton(pBtn,btn_Operation_Char_Percent);
    37. pG->addWidget(pBtn,3,0,1,1);
    38. pBtn = new QPushButton("_");
    39. m_pBtnGroup->addButton(pBtn,btn_Operation_Char_Underline);
    40. pG->addWidget(pBtn,3,1,1,1);
    41. pBtn = new QPushButton("()");
    42. m_pBtnGroup->addButton(pBtn,btn_Operation_Char_Brackets);
    43. pG->addWidget(pBtn,3,2,1,2);
    44. pBtn = new QPushButton("Not");
    45. m_pBtnGroup->addButton(pBtn,btn_Operation_Key_Not);
    46. pG->addWidget(pBtn,3,4,1,2);
    47.  
    48. pBtn = new QPushButton("Is");
    49. m_pBtnGroup->addButton(pBtn,btn_Operation_Key_Is);
    50. pG->addWidget(pBtn,4,0,1,2);
    51. pBtn = new QPushButton("获取属性值");
    52. m_pBtnGroup->addButton(pBtn,btn_Obtain_Fields_Values);
    53. pG->addWidget(pBtn,4,2,1,4);
    54.  
    55. return pG;
    56. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    Last edited by wysota; 28th April 2009 at 20:01.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Why QGridLayout works wrong??

    There is a difference between [ QTCLASS ]:
    QGridLayout* CDlgAttributesQuery::createOperationBtns()
    {
    QPushButton* pBtn;
    QGridLayout* pG = new QGridLayout;

    and [ CODE ]:
    Qt Code:
    1. QGridLayout* CDlgAttributesQuery::createOperationBtns()
    2. {
    3. QPushButton* pBtn;
    To copy to clipboard, switch view to plain text mode 
    See the difference?

    And then, your picture is quite right. what you probably mean is, that the buttons "_" and "%" should only be half wide as the others but that is achieved with the size policy and not through the layout alone. QPushButton::setSizePolicy()

  3. #3
    Join Date
    Aug 2008
    Posts
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: Why QGridLayout works wrong??

    I have made a mistake, I should use for the C++ codes, It's looks better!

    Qt Code:
    1. QGridLayout* CDlgAttributesQuery::createOperationBtns()
    2. {
    3.  
    4. pBtn = new QPushButton("=");
    5. m_pBtnGroup->addButton(pBtn,btn_Operation_Equal_To);
    6. pG->addWidget(pBtn,0,0,1,2);
    7. pBtn = new QPushButton("<>");
    8. m_pBtnGroup->addButton(pBtn,btn_Operation_Not_Equal);
    9. pG->addWidget(pBtn,0,2,1,2);
    10. pBtn = new QPushButton("Like");
    11. m_pBtnGroup->addButton(pBtn,btn_Operation_Key_Like);
    12. pG->addWidget(pBtn,0,4,1,2);
    13.  
    14. pBtn = new QPushButton(">");
    15. m_pBtnGroup->addButton(pBtn,btn_Operation_Greater_Than);
    16. pG->addWidget(pBtn,1,0,1,2);
    17. pBtn = new QPushButton(">=");
    18. m_pBtnGroup->addButton(pBtn,btn_Operation_Greater_Equal);
    19. pG->addWidget(pBtn,1,2,1,2);
    20. pBtn = new QPushButton("And");
    21. m_pBtnGroup->addButton(pBtn,btn_Operation_Key_And);
    22. pG->addWidget(pBtn,1,4,1,2);
    23.  
    24. pBtn = new QPushButton("<");
    25. m_pBtnGroup->addButton(pBtn,btn_Operation_Smaller_Than);
    26. pG->addWidget(pBtn,2,0,1,2);
    27. pBtn = new QPushButton("<=");
    28. m_pBtnGroup->addButton(pBtn,btn_Operation_Smaller_Equal);
    29. pG->addWidget(pBtn,2,2,1,2);
    30. pBtn = new QPushButton("Or");
    31. m_pBtnGroup->addButton(pBtn,btn_Operation_Key_Or);
    32. pG->addWidget(pBtn,2,4,1,2);
    33.  
    34. pBtn = new QPushButton("%");
    35. m_pBtnGroup->addButton(pBtn,btn_Operation_Char_Percent);
    36. pG->addWidget(pBtn,3,0,1,1);
    37. pBtn = new QPushButton("_");
    38. m_pBtnGroup->addButton(pBtn,btn_Operation_Char_Underline);
    39. pG->addWidget(pBtn,3,1,1,1);
    40. pBtn = new QPushButton("()");
    41. m_pBtnGroup->addButton(pBtn,btn_Operation_Char_Brackets);
    42. pG->addWidget(pBtn,3,2,1,2);
    43. pBtn = new QPushButton("Not");
    44. m_pBtnGroup->addButton(pBtn,btn_Operation_Key_Not);
    45. pG->addWidget(pBtn,3,4,1,2);
    46.  
    47. pBtn = new QPushButton("Is");
    48. m_pBtnGroup->addButton(pBtn,btn_Operation_Key_Is);
    49. pG->addWidget(pBtn,4,0,1,2);
    50. pBtn = new QPushButton("获取属性值");
    51. m_pBtnGroup->addButton(pBtn,btn_Obtain_Fields_Values);
    52. pG->addWidget(pBtn,4,2,1,4);
    53.  
    54. return pG;
    55. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Aug 2008
    Posts
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why QGridLayout works wrong??

    hello, Lykurg, I want to know how to call QPushButton::setSizePolcyThe fellowing code do not work.
    Qt Code:
    1. pBtn = new QPushButton("%");
    2. m_pBtnGroup->addButton(pBtn,btn_Operation_Char_Percent);
    3. pBtn->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
    4. pG->addWidget(pBtn,3,0,1,1);
    5. pBtn = new QPushButton("_");
    6. pBtn->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Fixed);
    7. m_pBtnGroup->addButton(pBtn,btn_Operation_Char_Underline);
    8. pG->addWidget(pBtn,3,1,1,1);
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Why QGridLayout works wrong??

    Hi, I just recognized that in your specific case QGridLayout::setColumnStretch() do the work.

    Edit: A good thing to figure out such problem can be to play around in Qt Designer even if you later want to code the layout yourself.

  6. #6
    Join Date
    Aug 2008
    Posts
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why QGridLayout works wrong??

    Thank you for your suggestion, I have solve my problem!

  7. #7
    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: Why QGridLayout works wrong??

    Please read what you post before posting it. That's what the "preview" button is for. Then correct your post to save people the pain of reading a post that is hardly readable. And even after submitting a post you have some time to edit it. Please be nice to people willing to help you.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QextSerialPort reading error: wrong values
    By Lawand in forum Qt Programming
    Replies: 9
    Last Post: 6th May 2009, 19:29
  2. Replies: 1
    Last Post: 30th March 2009, 22:25
  3. QGridLayout XY position
    By paule22 in forum Newbie
    Replies: 2
    Last Post: 9th August 2008, 18:42
  4. Delete a QGridLayout and New QGridLayout at runtime
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 5th November 2007, 13:01
  5. Qt 3.3 QGridLayout
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 23rd February 2007, 17:40

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.