Results 1 to 2 of 2

Thread: Help with alignment

  1. #1
    Join Date
    Oct 2007
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Help with alignment

    Hi,

    Im having trouble in aligning my QComboBox, and my exit button. I want them to be like the image that i have attached (in the center, in the right hand corner of the window), i have aligned them, but i must've did something wrong.

    Here is my code:

    Qt Code:
    1. #include <QLabel>
    2. #include <QPushButton>
    3. #include <QGraphicsView>
    4. #include <QLineEdit>
    5. #include <QHBoxLayout>
    6. #include <QVBoxLayout>
    7. #include <QPushButton>
    8. #include <QApplication>
    9. #include <QCheckBox>
    10. #include <QSpacerItem>
    11. #include <QLineEdit>
    12. #include <QGroupBox>
    13. #include <QComboBox>
    14. #include "browseimages.h"
    15.  
    16. BrowseImages::BrowseImages(QWidget *parent) : QWidget(parent)
    17. {
    18. // Title of the window
    19. this->setWindowTitle("Image Browser");
    20. this->resize(700, 400);
    21.  
    22. b_search = new QPushButton(tr("SEARCH"));
    23.  
    24. b_exit = new QPushButton(tr("Exit"));
    25.  
    26. combo = new QComboBox (this);
    27.  
    28. QHBoxLayout *h_exit = new QHBoxLayout;
    29. h_exit->addStretch();
    30. h_exit->addWidget(b_exit);
    31. h_exit->addStretch();
    32.  
    33. connect(b_exit, SIGNAL(clicked()), qApp, SLOT(quit()));
    34.  
    35. l_welcome = new QLabel(tr("--Image Browser--"));
    36. l_welcome->setFont(QFont("Times", 18, QFont::Bold));
    37. l_welcome->setAlignment(Qt::AlignCenter);
    38.  
    39. g_graphics = new QGraphicsView(this);
    40.  
    41. t_box = new QGroupBox(this);
    42. //t_box= new QGroupBox(tr("Tool Box"));
    43. t_box->setFixedSize(150,270);
    44.  
    45.  
    46. v_g->setAlignment(Qt::AlignCenter);
    47. v_g->addWidget(g_graphics);
    48. v_g->addWidget(t_box);
    49.  
    50. v_e->setAlignment(Qt::AlignRight);
    51. v_e->addWidget(combo);
    52.  
    53. v_m->setAlignment(Qt::AlignRight);
    54. v_m->addWidget(b_exit);
    55.  
    56. /*QHBoxLayout *v_w= new QHBoxLayout;
    57. v_w->setAlignment(Qt::AlignRight);
    58. v_w->addWidget(v_e);
    59. v_w->addWidget(v_m);*/
    60.  
    61.  
    62.  
    63. //--------------------------------//
    64. QHBoxLayout *sub1 = new QHBoxLayout;
    65. sub1->setAlignment(Qt::AlignRight);
    66. cb1= new QCheckBox(tr("Search By Plate Number"));
    67. sub1->addWidget(cb1);
    68.  
    69. QHBoxLayout *sub2 = new QHBoxLayout;
    70. sub2->setAlignment(Qt::AlignRight);
    71. l1= new QLineEdit(this);
    72. sub2->addWidget(l1);
    73.  
    74. QHBoxLayout *sub3 = new QHBoxLayout;
    75. sub3->setAlignment(Qt::AlignLeft);
    76. cb2= new QCheckBox(tr("Search By Date"));
    77. sub3->addWidget(cb2);
    78.  
    79.  
    80. QHBoxLayout *sub4 = new QHBoxLayout;
    81. sub4->setAlignment(Qt::AlignLeft);
    82. l2= new QLineEdit(this);
    83. sub4->addWidget(l2);
    84.  
    85. QHBoxLayout *sub5 = new QHBoxLayout;
    86. sub5->setAlignment(Qt::AlignCenter);
    87. b_ok= new QPushButton(tr("OK"));
    88. b_ok->setFixedHeight(20);
    89. sub5->addWidget(b_ok);
    90.  
    91.  
    92. QVBoxLayout *mainsub = new QVBoxLayout;
    93. mainsub->setAlignment(Qt::AlignRight);
    94. mainsub->addLayout(sub1);
    95. mainsub->addLayout(sub2);
    96. mainsub->addSpacing(40);
    97. mainsub->addLayout(sub3);
    98. mainsub->addLayout(sub4);
    99. mainsub->addLayout(sub5);
    100. t_box->setLayout(mainsub);
    101.  
    102. //------------------------------------------//
    103.  
    104.  
    105. QVBoxLayout *layout_vert = new QVBoxLayout;
    106. layout_vert->setAlignment(Qt::AlignCenter);
    107. layout_vert->addWidget(l_welcome);
    108. layout_vert->addLayout(v_g);
    109. layout_vert->addLayout(v_e);
    110. layout_vert->addSpacing(20);
    111. layout_vert->addLayout(v_m);
    112. this->setLayout(layout_vert);
    113. }
    To copy to clipboard, switch view to plain text mode 


    Thank you very much.
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Help with alignment

    It's simply painful to read and to try to understand complex and hand made layouting code. Seems you are able to do it with Qt Designer (even if it's missing layouts though) so may I ask why aren't you using it then?
    J-P Nurmi

Similar Threads

  1. QPushButton, stylesheets, text alignment
    By SiLiZiUMM in forum Qt Programming
    Replies: 1
    Last Post: 4th July 2007, 20:53
  2. Widget alignment.
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2007, 20:09
  3. Reg - QTable | Column alignment
    By suresh in forum Newbie
    Replies: 1
    Last Post: 18th December 2006, 16:58
  4. Regarding alignment in QTable
    By joseph in forum Qt Programming
    Replies: 4
    Last Post: 5th December 2006, 11:35
  5. How to set the alignment in a TableView?
    By vratojr in forum Qt Programming
    Replies: 1
    Last Post: 9th March 2006, 14:21

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.