levels.h
Qt Code:
  1. #ifndef MYWINDOW_H
  2. #define MYWINDOW_H
  3.  
  4. #include <QPushButton>
  5. #include <QMessageBox>
  6. #include <QMainWindow>
  7. #include <QHBoxLayout>
  8. #include "QScrollArea"
  9. #include "QImage"
  10. #include "QLabel"
  11. #include "QWidget"
  12. #include "QVBoxLayout"
  13. #include "QGroupBox"
  14. #include "QSpacerItem"
  15. #include "QList"
  16.  
  17. class Levels: public QMainWindow
  18. {
  19. Q_OBJECT
  20.  
  21. public:
  22. Levels(){};
  23. ~ Levels(){};
  24. void erzeugen();
  25. void setzeBilder();
  26. private:
  27. QVBoxLayout *ramen;
  28. QVBoxLayout *layout;
  29. QImage *image;
  30. QList<QLabel *> labels;
  31. QPushButton *back;
  32. QWidget *central;
  33. QGroupBox *box;
  34. QScrollArea *area;
  35. QSpacerItem *space;
  36. QList<QString> bilder;
  37.  
  38.  
  39. //public slots:
  40. };
  41. #endif
To copy to clipboard, switch view to plain text mode 


Qt Code:
  1. #include "levels.h"
  2.  
  3. void Levels::erzeugen()
  4. {
  5. setzeBilder();
  6. central=new QWidget(this);
  7. ramen= new QVBoxLayout(central);
  8. setCentralWidget(central);
  9. box = new QGroupBox;
  10. back = new QPushButton(" ? Back");
  11. for(int i=0;i<12;i++)
  12. {
  13. labels << new QLabel();
  14. }
  15. for(int i=0;i<12;i++)
  16. {
  17. labels.at(i)->setBackgroundRole(QPalette::Dark);
  18. labels.at(i)->setAutoFillBackground(true);
  19. image = new QImage(bilder.at(i));//Muss im debug-Ordner sein!!!
  20. labels.at(i)->setPixmap(QPixmap::fromImage(*image));
  21. labels.at(i)->setMaximumHeight(image->height());
  22. labels.at(i)->setMaximumWidth(image->width());
  23. }
  24.  
  25. space = new QSpacerItem(1,10);
  26. for(int i=0;i<12;i++)
  27. {
  28. layout->addWidget(labels.at(i));
  29. }
  30.  
  31.  
  32. box->setLayout(layout);
  33. area = new QScrollArea;
  34. area->setWidgetResizable(false);
  35. area->setWidget(box);
  36.  
  37. }
  38. void Levels::setzeBilder()
  39. {
  40. bilder.at(0)=QString::fromStdString("l01.png");
  41. bilder.at(1)=QString::fromStdString("l02.png");
  42. bilder.at(2)=QString::fromStdString("l03.png");
  43. bilder.at(3)=QString::fromStdString("l04.png");
  44. bilder.at(4)=QString::fromStdString("l05.png");
  45. bilder.at(5)=QString::fromStdString("l06.png");
  46. bilder.at(6)=QString::fromStdString("l07.png");
  47. bilder.at(7)=QString::fromStdString("l08.png");
  48. bilder.at(8)=QString::fromStdString("l09.png");
  49. bilder.at(9)=QString::fromStdString("l10.png");
  50. bilder.at(10)=QString::fromStdString("l11.png");
  51. bilder.at(11)=QString::fromStdString("l12.png");
  52.  
  53. }
To copy to clipboard, switch view to plain text mode 

Errors

problem.jpg

@ZikO
If i make the QList public and include the levels.h in another class (the class from where levels is called), can i add elements to the QList directly in the class where i initialize levels?
@d_stranz
I don't really know how to initialize it your way. I know I'm quite bad at c++
Normaly I'm develloping in java or c# (much easyer, but my nokia device does't support java oder c#)