GridLayout and ScrollArea
-
I have a scrollArea wich contains a list of widgets (progressbar, label,tool button)
@
gridl->addWidget(w);
ui->scroll->setLayout(gridl);
@
gridl is a gridLayout.Is it possible to update widgets position on click event?
for exemple: switching between lines (line3<--line2, line2<--line3)
I'm obliged to call @ui->scroll->setLayout(gridl);@ when I make some changes on the GridLayout
I'm lost please help me. -
[quote author="fouffa89" date="1365158146"]
Is it possible to update widgets position on click event?
[/quote]What about QScrollArea mouse events methods?
-
I have no idea how to do it but I will search for some example , thanks a lot , your post was helpful.
-
another solution would be to have a method in which you create a new gridLayout, add the existing items to that layout, call scrollArea->layout()->deleteLater(); and after call scrollArea->setLayout(new gridLayout);
-
yes this is my solution for now but I'm searching for the best solution to do it. The problem is how to make some changes without loading all the gridlayout?
-
I don't understand why you need to load whole layout. I tried myself and every change in layout is visible automatically (Qt5.0.2, VS2012). See below at my simple test, it changes layout after 5 seconds in timer event (moves label '3' from position 4 to 1). Please, forgive slummy example, I used box layout instead of grid for simplicity.
@
#include <QtWidgets\qapplication.h>
#include <QtWidgets\qwidget.h>
#include <QtWidgets\qscrollarea.h>
#include <QtWidgets\qlabel.h>
#include <QtWidgets\qboxlayout.h>
#include <QtCore\qstring.h>class MyScrollArea
: public QScrollArea
{
public:
MyScrollArea()
{
//prepare layout elements
m_mainLayout = new QVBoxLayout;for ( int i = 0; i < 10; ++i )
{
QLabel * label( new QLabel( QString::number( i ) ) );
m_mainLayout->addWidget( label );
m_labels.push_back( label );
}//set layout container
QWidget *widget( new QWidget );
widget->setLayout( m_mainLayout );
setWidget( widget );//start timer
startTimer( 5000 );
}void timerEvent( QTimerEvent * )
{
//change layout
m_mainLayout->removeWidget( m_labels[ 3 ] );
m_mainLayout->insertWidget( 0, m_labels[ 3 ] );
}QVBoxLayout m_mainLayout;
QVector< QLabel > m_labels;};
int main( int _argc, char** _argv )
{
QApplication app( _argc, _argv );MyScrollArea scrollArea;
scrollArea.setMaximumHeight( 100 );
scrollArea.show();return app.exec();
}
@ -
You're right , I never thought that it was as simple as that ,Thanks a lot!