Results 1 to 3 of 3

Thread: QGridLayout force column creation

  1. #1
    Join Date
    Feb 2013
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Question QGridLayout force column creation

    Hello. I have QGridLayout inside of QScrollArea.
    I'm trying to to add in it an image using this code:
    Qt Code:
    1. QWidget *target = findChild<QWidget*>("imagesBoxContent");
    2. QGridLayout *targetLayout = target->findChild<QGridLayout*>("gridLayout");
    3. foreach (QString imagePath, list)
    4. {
    5. QLabel *newItem = new QLabel(target);
    6. newItem->setMinimumHeight(50);
    7. newItem->setMaximumHeight(50);
    8. newItem->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Fixed);
    9. QImage image(imagePath);
    10. newItem->setPixmap(QPixmap::fromImage(image.scaledToHeight(50)));
    11. targetLayout->addWidget(newItem);
    12. }
    To copy to clipboard, switch view to plain text mode 
    And I get this result:
    Снимок.PNG
    But I'm trying to get this result:
    Снимок_.jpg
    How to make the QGridLayout create columns?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QGridLayout force column creation

    Nice pics but next time please use different ones. I am sorry for all women who are not rich enough to buy proper clothes, fitting their cup size...

    The function addWidget( QWidget * widget, int row, int column, Qt::Alignment alignment = 0 ) has more than one argument you might want to use them.

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

    Default Re: QGridLayout force column creation

    How to make the QGridLayout create columns?
    QGridLayout has ways to add widget in the columns, but will not help you get to what you want.

    you better look for Flow Layout Example
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Remove column from QGridLayout
    By enricong in forum Qt Programming
    Replies: 9
    Last Post: 20th August 2016, 12:37
  2. Replies: 1
    Last Post: 7th April 2011, 22:18
  3. QGridLayout: force all widget to the same size
    By Spooky in forum Qt Programming
    Replies: 2
    Last Post: 23rd March 2011, 14:58
  4. Delete a QGridLayout and New QGridLayout at runtime
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 5th November 2007, 14:01
  5. Limit number of row/column in QGridLayout
    By EricF in forum Qt Programming
    Replies: 2
    Last Post: 18th October 2007, 20:54

Tags for this Thread

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.