Results 1 to 9 of 9

Thread: Qt images example

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

    Default Qt images example

    Will someone please be so kind to post the full source code for this situation.
    SUppose I have this situation.

    I have 3 images that are bigger then the screen and two buttons at the end of them.
    (the images are bigger then the screens display)

    How can I show them on the phone screen ,I was thinking of using the QScrollarea but can't make it work .(note that I don't want a scroll bar for every image but a scroll bar that will scroll through all the images and buttons .

    Thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt images example

    You don't know how you want to display an image and you want us to provide a complete source code of that? So... basically you want us to write your program for you, with algorithm and everything, correct? Do you also want us to build it and deploy it on your phone or will providing the source code be enough to satisfy you?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: Qt images example

    I was expecting this answer . I tried to ask a more precise question but didn't get an answer,oh well this is my source code :
    How can I get all the data to fit the screen or add a scroolbar to all the grid .


    header

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




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

    Or if someone can write just the part on how to display multiple images in one scroll area.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt images example

    If you want to shrink an image, you have to do it yourself, QLabel is unable to shrink images, it can only expand them. Use QImage::scaled() or QPixmap::scaled() to get a scaled copy of the image. Then place the pixmap wherever you want it. If that's not what you are asking about then I don't understand what you are having problems with.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: Qt images example

    the problem is that i have a label with some text ,underneath it an image and underneth the image two buttons.
    Because of the image the buttons aren't visible on the screen. Only half of the image fits to the screen
    I want to be able to get to the buttons using a scrollbar , and I don't know how to do this .

    I want the solution to be viable when I rotatea the screen to landscape also.

    I've atached a picture with the problem



    Thanks .

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt images example

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: Qt images example

    I tried but the scroll bar doesn't apear.Can you please be a little more specific.


    Qt Code:
    1. QGridLayout *grid = new QGridLayout(this);
    2. scrollArea->setsetLayout(grid);
    To copy to clipboard, switch view to plain text mode 

  8. The following user says thank you to flogh for this useful post:

    thaihoangluu (22nd December 2011)

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt images example

    The code above is wrong. The layout should be set on a widget that gets put into the scroll area with setWidget() and the widget size should probably be controlled by the scroll area with setWidgetResizable(true). I can't say more unless you provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. The following 2 users say thank you to wysota for this useful post:

    flogh (8th December 2010), thaihoangluu (22nd December 2011)

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

    Cool Re: Qt images example

    Finally managed to resolve the defect thanks to Wysote (that explanation was extremelly helpfull.
    If someone has the same problem this was the solution:

    Qt Code:
    1. QVBoxLayout* grid = new QVBoxLayout(this);
    2.  
    3.  
    4. grid->addWidget(scr);
    5.  
    6. setLayout(grid);
    7.  
    8. QWidget *view = new QWidget(scr);
    9.  
    10. QVBoxLayout* viewLayout = new QVBoxLayout(view);
    11.  
    12. viewLayout->setAlignment( Qt::AlignTop );
    13.  
    14. view->setLayout(viewLayout);
    15.  
    16. scr->setWidget( view );
    17.  
    18. scr->setWidgetResizable(true);
    19.  
    20. scr->verticalScrollBar()->setSingleStep( 20 );
    21.  
    22.  
    23. qline = new QTextEdit("dadasaasdsadadadsasdadsadassdadasda");
    24.  
    25. qline->setReadOnly(true);
    26.  
    27. viewLayout->addWidget(qline,0,0);
    To copy to clipboard, switch view to plain text mode 
    all other widgets are added to viewLayout (viewLayout->addWidget)

  12. The following user says thank you to flogh for this useful post:

    thaihoangluu (22nd December 2011)

Similar Threads

  1. Replies: 1
    Last Post: 16th November 2010, 17:45
  2. Images
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2009, 15:22
  3. help: about images
    By miguel_mark in forum Qt Programming
    Replies: 2
    Last Post: 8th December 2009, 07:10
  4. Replies: 4
    Last Post: 27th July 2009, 15:45
  5. Qt 4.4.0 printing images
    By ad5xj in forum Newbie
    Replies: 1
    Last Post: 3rd June 2008, 23:07

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.