Results 1 to 6 of 6

Thread: Check box text too long

  1. #1
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Post Check box text too long

    Please can you please help me repair my code.Because of the check box ,my 2 buttons stretch more then they should and the check box label isn't displayed correctly it stretches out of the telephone screen. I tried with a scroll bar and area but it didn't work.
    Thank you very much.


    Qt Code:
    1. [QTCLASS]
    2. #ifndef Chestionar_H
    3. #define Chestionar_H
    4.  
    5. #include <QWidget>
    6. #include <QListWidgetItem>
    7. #include <QListWidget>
    8. #include <QLabel>
    9.  
    10.  
    11. QT_BEGIN_NAMESPACE
    12. class QGroupBox;
    13. class QTextEdit;
    14. QT_END_NAMESPACE
    15.  
    16.  
    17.  
    18. class Chestionar : public QWidget
    19. {
    20. Q_OBJECT
    21. public slots:
    22. void listItemClicked();
    23. public:
    24. Chestionar(QWidget *parent = 0);
    25.  
    26. void setWindowFlags(Qt::WindowFlags flags);
    27.  
    28.  
    29. private:
    30. QGroupBox *createFirstExclusiveGroup();
    31. QGroupBox *createNonExclusiveGroup();
    32. QGroupBox *groupBox2;
    33. QTextEdit *textEdit;
    34. QLabel *topLevelLabel;
    35. QPushButton *closeButton;
    36. QPushButton *closeButton2;
    37. QListWidget *list;
    38.  
    39. };
    40.  
    41. #endif
    42.  
    43.  
    44. [/QTCLASS]
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. [QTCLASS]
    2.  
    3. #include <QtGui>
    4. #include "chestionar.h"
    5.  
    6.  
    7. Chestionar::Chestionar(QWidget *parent)
    8. : QWidget(parent)
    9. {
    10. nr_rand = 0;
    11. variante_rasp = 0;
    12. lines = new QStringList;
    13. raspuns_corect ="Da";
    14. setAttribute(Qt::WA_DeleteOnClose);
    15. rg = 0;
    16. //scrollArea->setBackgroundRole(QPalette::Dark);
    17. QGridLayout *grid = new QGridLayout(this);
    18. // scrollArea->setsetLayout(grid);
    19.  
    20. qline = new QTextEdit("dadasaasdsadadadsasdadsadassdadasda");
    21. qline->setReadOnly(true);
    22. // grid->addWidget(qline,0,0);
    23.  
    24. ///aa
    25.  
    26. ///aa
    27.  
    28. QScrollArea *scroll=new QScrollArea();
    29.  
    30. scroll->setWidget(qline);
    31. //scroll->sets
    32. scroll->setAlignment(Qt::AlignLeft);
    33. // scroll->setWidgetResizable(true);
    34. //scroll->widget()->resize();
    35. // scroll->setBackgroundRole(QPalette::Dark);// set background of scroll Area
    36. //qline->updateGeometry();
    37. grid->addWidget(scroll,0,0);
    38. //////////////////////////
    39.  
    40.  
    41. radio1 = new QRadioButton(tr("&Radio busssssssssxxxxxxxxxxxxxxxxxxxxxxxxxtssssssssssssssssssssssssssssssssssssssssssssssssssston 1"));
    42. radio1->setMaximumWidth(10);;
    43. radio2 = new QRadioButton(tr("R&adio ssssssssxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxsssssssssssssssssssssssssssssssssssssssssssssssssbutton 2"));
    44. radio3 = new QRadioButton(tr("Ra&dio bssssxxxxxxxxxxxxxxxxxxxxxxxxxxxxxsssssssssssssssssssssssssssssssssssutton 3"));
    45.  
    46. radio1->setChecked(true);
    47.  
    48. grid->addWidget(radio1,1,0);
    49. grid->addWidget(radio2,2,0);
    50. grid->addWidget(radio3,3,0);
    51.  
    52. QWidget *d = QApplication::desktop();
    53. int32_t w=d->width();
    54.  
    55. radio1->setMaximumWidth(w);
    56.  
    57.  
    58. ///////////////////
    59.  
    60. //grid->addWidget(createFirstExclusiveGroup(), 1, 0);
    61. setLayout(grid);
    62. setWindowTitle(tr("xxx"));
    63. // poza
    64. topLevelLabel = new QLabel("&xxx:", this);
    65. topLevelLabel->setText("sda");
    66. QPixmap pixmap(":/image/i.png");
    67. pixmap.scaledToHeight(30, Qt::SmoothTransformation);
    68. pixmap.scaledToWidth(50, Qt::SmoothTransformation);
    69. topLevelLabel->setPixmap(pixmap);
    70.  
    71. topLevelLabel->setMask(pixmap.mask());
    72. topLevelLabel->show();
    73. grid->addWidget(topLevelLabel,4,0);
    74.  
    75. // poza
    76.  
    77. grid->addWidget(createNonExclusiveGroup(), 5, 0);
    78. /*
    79.   QVBoxLayout *layout = new QVBoxLayout;
    80.   layout->addWidget(textEdit);
    81.   layout->addWidget(closeButton);
    82.   setLayout(layout);
    83. */
    84. groupBox2->setTitle("ssssssssssssss");
    85. qline->setText("testing"); ;
    86. radio1->setText("dsa");
    87. radio2->setText("dsada");
    88. radio3->setText("adsdaddsadau");
    89. }
    90.  
    91. QGroupBox *Chestionar::createNonExclusiveGroup()
    92. {
    93. groupBox2 = new QGroupBox(tr("Non-Exclusive Checkboxes"));
    94. groupBox2->setFlat(true);
    95. //! [7]
    96.  
    97. //! [8]
    98. closeButton = new QPushButton(tr("xxxxxxxxxxx"));
    99. connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
    100.  
    101. closeButton2 = new QPushButton(tr("&xxxxxxxxxxxxx"));
    102. connect(closeButton2, SIGNAL(clicked()), this, SLOT(urmatoareaslot()));
    103.  
    104. //! [8]
    105.  
    106.  
    107. //! [9]
    108. QVBoxLayout *vbox = new QVBoxLayout;
    109. vbox->addWidget(closeButton2);
    110. vbox->addWidget(closeButton);
    111. // vbox->addStretch(1);
    112. groupBox2->setLayout(vbox);
    113.  
    114. return groupBox2;
    115. }
    116.  
    117.  
    118. void Chestionar::setWindowFlags(Qt::WindowFlags flags)
    119.  
    120. {
    121. QWidget::setWindowFlags(flags);
    122.  
    123. QString text;
    124.  
    125. Qt::WindowFlags type = (flags & Qt::WindowType_Mask);
    126. if (type == Qt::Window) {
    127. text = "Qt::Window";
    128. } else if (type == Qt::Dialog) {
    129. text = "Qt::Dialog";
    130. } else if (type == Qt::Sheet) {
    131. text = "Qt::Sheet";
    132. } else if (type == Qt::Drawer) {
    133. text = "Qt::Drawer";
    134. } else if (type == Qt::Popup) {
    135. text = "Qt::Popup";
    136. } else if (type == Qt::Tool) {
    137. text = "Qt::Tool";
    138. } else if (type == Qt::ToolTip) {
    139. text = "Qt::ToolTip";
    140. } else if (type == Qt::SplashScreen) {
    141. text = "Qt::SplashScreen";
    142. }
    143.  
    144. if (flags & Qt::MSWindowsFixedSizeDialogHint)
    145. text += "\n| Qt::MSWindowsFixedSizeDialogHint";
    146. if (flags & Qt::X11BypassWindowManagerHint)
    147. text += "\n| Qt::X11BypassWindowManagerHint";
    148. if (flags & Qt::FramelessWindowHint)
    149. text += "\n| Qt::FramelessWindowHint";
    150. if (flags & Qt::WindowTitleHint)
    151. text += "\n| Qt::WindowTitleHint";
    152. if (flags & Qt::WindowSystemMenuHint)
    153. text += "\n| Qt::WindowSystemMenuHint";
    154. if (flags & Qt::WindowMinimizeButtonHint)
    155. text += "\n| Qt::WindowMinimizeButtonHint";
    156. if (flags & Qt::WindowMaximizeButtonHint)
    157. text += "\n| Qt::WindowMaximizeButtonHint";
    158. if (flags & Qt::WindowContextHelpButtonHint)
    159. text += "\n| Qt::WindowContextHelpButtonHint";
    160. if (flags & Qt::WindowShadeButtonHint)
    161. text += "\n| Qt::WindowShadeButtonHint";
    162. if (flags & Qt::WindowStaysOnTopHint)
    163. text += "\n| Qt::WindowStaysOnTopHint";
    164. if (flags & Qt::CustomizeWindowHint)
    165. text += "\n| Qt::CustomizeWindowHint";
    166.  
    167. textEdit->setPlainText(text);
    168. }
    169.  
    170. void Chestionar::listItemClicked()
    171. {
    172. QMessageBox::warning(this, "Gresit", QString("xxxxxxxxxxxxxx: "));
    173. topLevelLabel->setText("xxxxxxxxxxxx");
    174. }
    175.  
    176. void Chestionar::urmatoareaslot()
    177. {
    178.  
    179.  
    180. }//in plus
    181.  
    182.  
    183.  
    184.  
    185. [/QTCLASS]
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: Check box text too long

    I didn't quite understand your problem, maybe a print-screen (of the simulator) will help us better understand it.

    But from what i have understand you want some widgets (buttons) to expand less than the other widgets in the layout, that can be achieved by editing the QSizePolicy of the widgets, something like this Note: i don't remember the "formula" for the stretch factor, so play with the values.

    Or, do you really need that long text and just display a scroll-bar?
    Last edited by Zlatomir; 19th November 2010 at 22:32.

  3. #3
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Check box text too long

    Firstly thank you very much for the quick answer.
    The main problem is that I want to display the whole text in the check box label (that is longer then the screen size) and I don't know how to achive this .

  4. #4
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Check box text too long

    Is it possible to have the label of the checkbox on multiple rows ?

  5. #5
    Join Date
    Sep 2010
    Location
    Ontario Canada
    Posts
    23
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Symbian S60 Maemo/MeeGo

    Default Re: Check box text too long

    Set the word wrap property of the label.
    Qt Code:
    1. label->setWordWrap(true);
    To copy to clipboard, switch view to plain text mode 
    Cheers,
    Jon

  6. #6
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Check box text too long

    Unfortunately this doesn't solve the problem .The grid doesn't stretch to the mobile screen.
    The label stretches to the text but gets out of the screen.
    How can I make my grid stretch to the mobile screen?


    Thank you.

Similar Threads

  1. QCheckBox with long text label
    By Ferdous in forum Newbie
    Replies: 5
    Last Post: 29th October 2011, 19:05
  2. QListWidgetItem text too long
    By jcr in forum Qt Programming
    Replies: 3
    Last Post: 20th October 2010, 00:19
  3. draw long text in rect
    By yxtx1984 in forum Qt Programming
    Replies: 1
    Last Post: 21st January 2010, 09:00
  4. buton text long ?
    By electronicboy in forum General Programming
    Replies: 3
    Last Post: 2nd November 2009, 10:21
  5. Layout long text in QTableWidget
    By Tamtam in forum Newbie
    Replies: 0
    Last Post: 13th February 2009, 15:09

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.