Results 1 to 3 of 3

Thread: Dynamic QscrollArea

  1. #1
    Join Date
    Jul 2011
    Posts
    6
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Dynamic QscrollArea

    Hello guys I have a problem ..
    When I want to enter new parameters in the Qscroll area, put out from the new parameters and do not see the QscrollBar. I wish it were all dynamic, that when I post a new parameter, inserts it into the area by changing the bar ... how do I?? help!!

    file .h
    Qt Code:
    1. class ParamPage : public QWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. ParamPage(QWidget *parent = 0);
    6. QString text;
    7. QString prev;
    8. QLabel *label;
    9. QLineEdit *lineEdit;
    10. QPushButton *parButton;
    11. QPushButton *modButton;
    12. QLabel *pathLabel;
    13. QLineEdit *fileNameEdit;
    14. int num;
    15. QLineEdit *edit[10];
    16. int lineNumber;
    17. QStringList listFileData;
    18. QScrollArea *scrollArea;
    19. QRect desktopGeometry;
    20. void writeToFile();
    21. void reactToSIP();
    22.  
    23. private slots:
    24. void paramClicked();
    25. void modifClicked();
    26. void desktopResized(int screen);
    27.  
    28.  
    29. };
    30.  
    31.  
    32.  
    33. #endif
    To copy to clipboard, switch view to plain text mode 



    file .cpp
    Qt Code:
    1. ParamPage::ParamPage(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4.  
    5. desktopGeometry = QApplication::desktop()->availableGeometry(0);
    6. scrollArea = new QScrollArea(this);
    7.  
    8. QGroupBox *configGroup = new QGroupBox(scrollArea);
    9. QGridLayout *gridLayout = new QGridLayout(configGroup);
    10. configGroup->setLayout(gridLayout);
    11.  
    12. parButton = new QPushButton(configGroup);
    13. parButton->setText("new_par");
    14. modButton = new QPushButton(configGroup);
    15. modButton->setText("add par");
    16. pathLabel = new QLabel(configGroup);
    17. pathLabel->setText("File");
    18. fileNameEdit = new QLineEdit(configGroup);
    19. // QLabel *serverLabel = new QLabel(tr("Server:"));
    20.  
    21. //QComboBox *serverCombo = new QComboBox;
    22. //serverCombo->addItem(tr("Trolltech (Australia)"));
    23. //serverCombo->addItem(tr("Trolltech (Germany)"));
    24. //serverCombo->addItem(tr("Trolltech (Norway)"));
    25. //serverCombo->addItem(tr("Trolltech (People's Republic of China)"));
    26. //serverCombo->addItem(tr("Trolltech (USA)"));
    27. gridLayout->addWidget( parButton);
    28. gridLayout->addWidget(modButton);
    29. gridLayout->addWidget(pathLabel);
    30. gridLayout->addWidget(fileNameEdit);
    31.  
    32. scrollArea->setWidget(configGroup);
    33. QHBoxLayout* layout = new QHBoxLayout();
    34. layout->addWidget(scrollArea);
    35. setLayout(layout);
    36. scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    37.  
    38.  
    39.  
    40. //serverLayout->addWidget(serverCombo);
    41.  
    42. connect(parButton, SIGNAL (clicked()), this, SLOT( paramClicked()));
    43. connect(modButton, SIGNAL (clicked()), this, SLOT( modifClicked()));
    44.  
    45. connect(QApplication::desktop(), SIGNAL(workAreaResized(int)),
    46. this, SLOT(desktopResized(int)));
    47.  
    48.  
    49. }
    50.  
    51. void ParamPage::desktopResized(int screen)
    52. {
    53. if (screen != 0)
    54. return;
    55. reactToSIP();
    56. }
    57.  
    58. void ParamPage::reactToSIP()
    59. {
    60. QRect availableGeometry = QApplication::desktop()->availableGeometry(0);
    61.  
    62. if (desktopGeometry != availableGeometry) {
    63. if (windowState() | Qt::WindowMaximized)
    64. setWindowState(windowState() & ~Qt::WindowMaximized);
    65.  
    66.  
    67.  
    68. setGeometry(availableGeometry);
    69. }
    70.  
    71. desktopGeometry = availableGeometry;
    72. }
    73.  
    74. void ParamPage::paramClicked(){
    75. bool ok;
    76. text = QInputDialog::getText(scrollArea, tr("Nuovo parametro"),
    77. tr("Nome parametro:"), QLineEdit::Normal,QDir::home().dirName(),
    78. &ok);
    79.  
    80. num = QInputDialog::getInteger(scrollArea, tr("Numero colonne"),tr("Percentage:"), 25, 0, 100, 1, &ok);
    81.  
    82. // QVBoxLayout *mainLayout = new QVBoxLayout;
    83.  
    84. // QLabel* l = new QLabel("new label", this);
    85. // mainLayout->addWidget(l,1,0);
    86. if(ok){
    87.  
    88. label = new QLabel(scrollArea);
    89. //label->adjustSize();
    90. //label->setIndent(15);
    91. //this->layout()->set
    92.  
    93. this->layout()->addWidget(label);
    94. label->setText(text);
    95. for(int i;i<num;i++){
    96. edit[i]=new QLineEdit(scrollArea);
    97. this->layout()->addWidget(edit[i]);
    98. }
    99.  
    100.  
    101. // mainLayout->addWidget(label,1,0);
    102.  
    103. // mainLayout->addWidget(label,3,0);
    104. // setLayout(mainLayout);
    105.  
    106. //lineEdit = new QLineEdit(this);
    107.  
    108. //lineEdit->set
    109. // this->layout()->addWidget(lineEdit);
    110.  
    111.  
    112.  
    113.  
    114. //layout()->addWidget(lineEdit);
    115. }
    116.  
    117.  
    118. }
    119.  
    120.  
    121. void ParamPage::modifClicked(){
    122. QString fileName =
    123. QFileDialog::getOpenFileName(this, tr("Open CFG File"),
    124. QDir::currentPath(),
    125. tr("CFG Files ( *.cfg)"));
    126. QFileInfo fileInfo(fileName);
    127.  
    128.  
    129. fileNameEdit->setText(fileInfo.absoluteFilePath());
    130. //pathValueLabel = new QLabel(fileInfo.fileName());
    131. // pathValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    132.  
    133. QFile file(fileName);
    134. if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    135. return ;
    136. QTextStream out(&file);
    137. prev="";
    138. lineNumber=0;
    139. while (!file.atEnd()) {
    140. QString line = file.readLine();
    141. listFileData.append(line);
    142. if(line.startsWith("Fine File")){
    143. //line=prev;
    144.  
    145. list = line.split(QRegExp("\\s+"));
    146. QString str;
    147. str.append("Exec ");
    148. str.append("/CODE/ScriptFiles/BatchModeRunning/");
    149. str.append("\n");
    150. str.append("Fine File");
    151. str.append(list[1]);
    152. listFileData.replace(lineNumber,str);
    153.  
    154.  
    155.  
    156. }
    157. // else{
    158. // prev= line;
    159. // }
    160. lineNumber ++;
    161. }
    162. writeToFile();
    163. }
    164.  
    165. void ParamPage::writeToFile(){
    166.  
    167. QFile file("Config_new.cfg");
    168. if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
    169. return;
    170.  
    171. QTextStream out(&file);
    172. for(int i = 0; i<listFileData.size(); i++)
    173. out << listFileData.at(i) << "\n";
    174. }
    To copy to clipboard, switch view to plain text mode 

    thankss!!!!

  2. #2
    Join Date
    Jul 2011
    Location
    Italy
    Posts
    24
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Dynamic QscrollArea

    I don't have time to look at your code, but this code works fine.

    I created a QMainwindow with just the scrollArea and a button.

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QVBoxLayout>
    4. #include <QFrame>
    5.  
    6. MainWindow::MainWindow(QWidget *parent) :
    7. QMainWindow(parent),
    8. ui(new Ui::MainWindow)
    9. {
    10. ui->setupUi(this);
    11.  
    12. m_Frame = new QFrame();
    13. ui->scrollArea->setWidget(m_Frame);
    14. m_Frame->setLayout(l);
    15.  
    16. connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
    17. }
    18.  
    19. MainWindow::~MainWindow()
    20. {
    21. delete ui;
    22. }
    23.  
    24. void MainWindow::onButtonClicked()
    25. {
    26. QPushButton* b = new QPushButton(this);
    27. m_Frame->layout()->addWidget(b);
    28. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by sakya; 19th July 2011 at 14:57.

  3. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Dynamic QscrollArea

    remove this line
    Qt Code:
    1. setLayout(layout);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 1
    Last Post: 20th January 2011, 17:17
  2. Dynamic updates of a QWidget in a QScrollArea
    By plamkata in forum Qt Programming
    Replies: 2
    Last Post: 20th July 2008, 23:45
  3. Replies: 2
    Last Post: 10th March 2008, 20:16
  4. QScrollArea
    By jimfan in forum Qt Programming
    Replies: 2
    Last Post: 29th February 2008, 06:57
  5. dynamic qscrollarea
    By hijinks in forum Qt Programming
    Replies: 3
    Last Post: 26th September 2006, 16:48

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
  •  
Qt is a trademark of The Qt Company.