1 Attachment(s)
Help me about QGridLayout and ScrollArea
Please help me this problem.
I using QGridLayout and array of QToolButton to display a array of images (Image is the icon of button). But the button (image) overlap...
I want to display the array button in 3 columns....
help me!
Thanks!
this is my code
Code:
QDir currentImageDir
(LibPath
+"/"+dir
);
currentImageDir.
setFilter(QDir::Files |
QDir::NoSymLinks |
QDir::NoDotAndDotDot);
QStringList ImageEntries
= currentImageDir.
entryList();
scrollArea->setWidgetResizable(true);
scrollArea->setWidget(contentsWidget);
contentsWidget->setLayout(gridEPG);
contentsWidget->setMinimumSize(scrollArea->width(), scrollArea->height());
ui->imageLayout->addWidget(scrollArea, 1, 0, 2, 3);
QString filename
[ImageEntries.
count()];
for (int x = 0; x < ImageEntries.count(); x++)
{
// int row = x;
//int col = i%3;
filename[x]= ImageEntries.at(x);
button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
button
->setIcon
(QIcon(LibPath
+ "/" + dir
+ "/" + filename
[x
]));
button
->setFixedSize
(QSize(96,
76));
button
->setIconSize
(QSize(96,
76));
connect(button, SIGNAL(clicked()), singalImageMapper, SLOT(map()));
singalImageMapper->setMapping(button, filename[x]);
for(int i=0; i<3; i++)
gridEPG->addWidget(button, x, i%3);
}
ui
->fileImgUsing
->setText
(QString(imgPath
+ "/" + dir
));
connect(singalImageMapper,
SIGNAL(mapped
(QString)),
this,
SIGNAL(clicked
(QString)));
connect(this,
SIGNAL(clicked
(QString)),
this,
SLOT(onButtonClicked
(QString)));
and my result
Attachment 9399
Re: Help me about QGridLayout and ScrollArea
[QUOTE=homerux;248996]
Code:
for(int i=0; i<3; i++)
gridEPG->addWidget(button, x, i%3);
You are trying to put the same button object in each of three columns? If that is what you intend then you need to duplicate the button for each column (i.e. three different objects with the same image). If that is not what you intended then remove the for loop and change "i % 3" to " x % 3".
Set the sizeConstraint() of the layout in the scroll area contents widget to QLayout::SetFixedSize and it should adjust the size of the contentsWidget to match the fixed size of the contained tool buttons.
Re: Help me about QGridLayout and ScrollArea
[QUOTE=ChrisW67;249013]
Quote:
Originally Posted by
homerux
Code:
for(int i=0; i<3; i++)
gridEPG->addWidget(button, x, i%3);
You are trying to put the same button object in each of three columns? If that is what you intend then you need to duplicate the button for each column (i.e. three different objects with the same image). If that is not what you intended then remove the for loop and change "i % 3" to " x % 3".
Set the sizeConstraint() of the layout in the scroll area contents widget to QLayout::SetFixedSize and it should adjust the size of the contentsWidget to match the fixed size of the contained tool buttons.
I want put a array of button in 3 columns in a scroll layout, but it not work. Can you help me?
Re: Help me about QGridLayout and ScrollArea
Code:
#include <QtGui>
{
Q_OBJECT
public:
for (int n = 0; n < 150; ++n) {
b
->setIcon
(qApp
->style
()->standardIcon
(QStyle::SP_FileIcon));
layout->addWidget(b, n / 3, n % 3);
}
contents->setLayout(layout);
setWidget(contents);
}
};
int main(int argc, char **argv)
{
Window w;
w.resize(200, 200);
w.show();
return app.exec();
}
#include "main.moc"