PDA

View Full Version : Check box text too long



flogh
19th November 2010, 21:34
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.




#ifndef Chestionar_H
#define Chestionar_H

#include <QWidget>
#include <QListWidgetItem>
#include <QListWidget>
#include <QLabel>


QT_BEGIN_NAMESPACE
class QGroupBox;
class QPushButton;
class QTextEdit;
QT_END_NAMESPACE



class Chestionar : public QWidget
{
Q_OBJECT
public slots:
void listItemClicked();
public:
Chestionar(QWidget *parent = 0);

void setWindowFlags(Qt::WindowFlags flags);


private:
QGroupBox *createFirstExclusiveGroup();
QGroupBox *createNonExclusiveGroup();
QGroupBox *groupBox2;
QTextEdit *textEdit;
QLabel *topLevelLabel;
QPushButton *closeButton;
QPushButton *closeButton2;
QListWidget *list;

};

#endif








#include <QtGui>
#include "chestionar.h"


Chestionar::Chestionar(QWidget *parent)
: QWidget(parent)
{
nr_rand = 0;
variante_rasp = 0;
lines = new QStringList;
raspuns_corect ="Da";
setAttribute(Qt::WA_DeleteOnClose);
rg = 0;
//scrollArea->setBackgroundRole(QPalette::Dark);
QGridLayout *grid = new QGridLayout(this);
// scrollArea->setsetLayout(grid);

qline = new QTextEdit("dadasaasdsadadadsasdadsadassdadasda");
qline->setReadOnly(true);
// grid->addWidget(qline,0,0);

///aa

///aa

QScrollArea *scroll=new QScrollArea();

scroll->setWidget(qline);
//scroll->sets
scroll->setAlignment(Qt::AlignLeft);
// scroll->setWidgetResizable(true);
//scroll->widget()->resize();
// scroll->setBackgroundRole(QPalette::Dark);// set background of scroll Area
//qline->updateGeometry();
grid->addWidget(scroll,0,0);
//////////////////////////


radio1 = new QRadioButton(tr("&Radio busssssssssxxxxxxxxxxxxxxxxxxxxxxxxxtsssssssssssss sssssssssssssssssssssssssssssssssssssston 1"));
radio1->setMaximumWidth(10);;
radio2 = new QRadioButton(tr("R&adio ssssssssxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxssssssssss sssssssssssssssssssssssssssssssssssssssbutton 2"));
radio3 = new QRadioButton(tr("Ra&dio bssssxxxxxxxxxxxxxxxxxxxxxxxxxxxxxssssssssssssssss sssssssssssssssssssutton 3"));

radio1->setChecked(true);

grid->addWidget(radio1,1,0);
grid->addWidget(radio2,2,0);
grid->addWidget(radio3,3,0);

QWidget *d = QApplication::desktop();
int32_t w=d->width();

radio1->setMaximumWidth(w);


///////////////////

//grid->addWidget(createFirstExclusiveGroup(), 1, 0);
setLayout(grid);
setWindowTitle(tr("xxx"));
// poza
topLevelLabel = new QLabel("&xxx:", this);
topLevelLabel->setText("sda");
QPixmap pixmap(":/image/i.png");
pixmap.scaledToHeight(30, Qt::SmoothTransformation);
pixmap.scaledToWidth(50, Qt::SmoothTransformation);
topLevelLabel->setPixmap(pixmap);

topLevelLabel->setMask(pixmap.mask());
topLevelLabel->show();
grid->addWidget(topLevelLabel,4,0);

// poza

grid->addWidget(createNonExclusiveGroup(), 5, 0);
/*
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(textEdit);
layout->addWidget(closeButton);
setLayout(layout);
*/
groupBox2->setTitle("ssssssssssssss");
qline->setText("testing"); ;
radio1->setText("dsa");
radio2->setText("dsada");
radio3->setText("adsdaddsadau");
}

QGroupBox *Chestionar::createNonExclusiveGroup()
{
groupBox2 = new QGroupBox(tr("Non-Exclusive Checkboxes"));
groupBox2->setFlat(true);
//! [7]

//! [8]
closeButton = new QPushButton(tr("xxxxxxxxxxx"));
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));

closeButton2 = new QPushButton(tr("&xxxxxxxxxxxxx"));
connect(closeButton2, SIGNAL(clicked()), this, SLOT(urmatoareaslot()));

//! [8]


//! [9]
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(closeButton2);
vbox->addWidget(closeButton);
// vbox->addStretch(1);
groupBox2->setLayout(vbox);

return groupBox2;
}


void Chestionar::setWindowFlags(Qt::WindowFlags flags)

{
QWidget::setWindowFlags(flags);

QString text;

Qt::WindowFlags type = (flags & Qt::WindowType_Mask);
if (type == Qt::Window) {
text = "Qt::Window";
} else if (type == Qt::Dialog) {
text = "Qt::Dialog";
} else if (type == Qt::Sheet) {
text = "Qt::Sheet";
} else if (type == Qt::Drawer) {
text = "Qt::Drawer";
} else if (type == Qt::Popup) {
text = "Qt::Popup";
} else if (type == Qt::Tool) {
text = "Qt::Tool";
} else if (type == Qt::ToolTip) {
text = "Qt::ToolTip";
} else if (type == Qt::SplashScreen) {
text = "Qt::SplashScreen";
}

if (flags & Qt::MSWindowsFixedSizeDialogHint)
text += "\n| Qt::MSWindowsFixedSizeDialogHint";
if (flags & Qt::X11BypassWindowManagerHint)
text += "\n| Qt::X11BypassWindowManagerHint";
if (flags & Qt::FramelessWindowHint)
text += "\n| Qt::FramelessWindowHint";
if (flags & Qt::WindowTitleHint)
text += "\n| Qt::WindowTitleHint";
if (flags & Qt::WindowSystemMenuHint)
text += "\n| Qt::WindowSystemMenuHint";
if (flags & Qt::WindowMinimizeButtonHint)
text += "\n| Qt::WindowMinimizeButtonHint";
if (flags & Qt::WindowMaximizeButtonHint)
text += "\n| Qt::WindowMaximizeButtonHint";
if (flags & Qt::WindowContextHelpButtonHint)
text += "\n| Qt::WindowContextHelpButtonHint";
if (flags & Qt::WindowShadeButtonHint)
text += "\n| Qt::WindowShadeButtonHint";
if (flags & Qt::WindowStaysOnTopHint)
text += "\n| Qt::WindowStaysOnTopHint";
if (flags & Qt::CustomizeWindowHint)
text += "\n| Qt::CustomizeWindowHint";

textEdit->setPlainText(text);
}

void Chestionar::listItemClicked()
{
QMessageBox::warning(this, "Gresit", QString("xxxxxxxxxxxxxx: "));
topLevelLabel->setText("xxxxxxxxxxxx");
}

void Chestionar::urmatoareaslot()
{


}//in plus

Zlatomir
19th November 2010, 22:27
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 (http://doc.qt.nokia.com/latest/qsizepolicy.html) of the widgets, something like this (http://www.qtcentre.org/threads/31768-Widget-size-in-layouts-with-different-screen-resolution-problem-S60?p=148179#post148179) 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?

flogh
20th November 2010, 12:23
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 .

flogh
20th November 2010, 23:13
Is it possible to have the label of the checkbox on multiple rows ?

Jon Heron
21st November 2010, 17:50
Set the word wrap property of the label.

label->setWordWrap(true);
Cheers,
Jon

flogh
22nd November 2010, 09:56
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.