C167
7th January 2008, 21:09
Hi there,
i created a QMainWindow with a toolbar and a QStackedWidget as central widget. This widget holds the content that should be displayed if one clicks a button in the toolbar. So for now, the main page that is dispayed at startup shows 5 different splash screens (simple images). Lets say it should. I'm using a connection from the actiongroup in the toolbar, to switch splashes when hovering a button in the toolbar.
My first version simply used a QLabel that got equipped with a pixmap. Problem: Its slow and if the user is to fast in moving over the toolar, the splashes come one after the other with some noticable delay.
I wanted to rewrite it using a QStackedLayout, but now the labels don't show up. If i set up a label without adding it to the Layout, it shows up just as it should. My code:
mainPage::mainPage( QWidget *parent ): QWidget( parent ) {
stack = new QStackedLayout( this );
setLayout( stack );
area0 = new QLabel( this );
area1 = new QLabel( this );
area2 = new QLabel( this );
area3 = new QLabel( this );
area4 = new QLabel( this );
stack->addWidget( area0 );
stack->addWidget( area1 );
stack->addWidget( area2 );
stack->addWidget( area3 );
stack->addWidget( area4 );
stack->setCurrentIndex( 0 );
// QLabel *test = new QLabel(this);
// test->setPixmap(QPixmap::fromImage(QImage(":/images/splash0.jpg")));
}
void mainPage::loadSplashes() {
area0->setPixmap( QPixmap::fromImage( QImage( ":images/splash0.jpg" ) ) );
area1->setPixmap( QPixmap::fromImage( QImage( ":images/splash1.jpg" ) ) );
area2->setPixmap( QPixmap::fromImage( QImage( ":images/splash2.jpg" ) ) );
area3->setPixmap( QPixmap::fromImage( QImage( ":images/splash3.jpg" ) ) );
area4->setPixmap( QPixmap::fromImage( QImage( ":images/splash4.jpg" ) ) );
}
void mainPage::showContent( QAction* action ) {
qDebug() << "showContent called: " << action->objectName();
if ( action->objectName() == "action_Show_Main" ) {
stack->setCurrentIndex( 0 );
} else if ( action->objectName() == "action_Show_Photos" ) {
stack->setCurrentIndex( 1 );
} else if ( action->objectName() == "action_Show_Movies" ) {
stack->setCurrentIndex( 2 );
} else if ( action->objectName() == "action_Show_Games" ) {
stack->setCurrentIndex( 3 );
} else if ( action->objectName() == "action_Show_Tools" ) {
stack->setCurrentIndex( 4 );
} else {
stack->setCurrentIndex( 0 );
}
}Why that? it's set up exactly like the central Widget.
i created a QMainWindow with a toolbar and a QStackedWidget as central widget. This widget holds the content that should be displayed if one clicks a button in the toolbar. So for now, the main page that is dispayed at startup shows 5 different splash screens (simple images). Lets say it should. I'm using a connection from the actiongroup in the toolbar, to switch splashes when hovering a button in the toolbar.
My first version simply used a QLabel that got equipped with a pixmap. Problem: Its slow and if the user is to fast in moving over the toolar, the splashes come one after the other with some noticable delay.
I wanted to rewrite it using a QStackedLayout, but now the labels don't show up. If i set up a label without adding it to the Layout, it shows up just as it should. My code:
mainPage::mainPage( QWidget *parent ): QWidget( parent ) {
stack = new QStackedLayout( this );
setLayout( stack );
area0 = new QLabel( this );
area1 = new QLabel( this );
area2 = new QLabel( this );
area3 = new QLabel( this );
area4 = new QLabel( this );
stack->addWidget( area0 );
stack->addWidget( area1 );
stack->addWidget( area2 );
stack->addWidget( area3 );
stack->addWidget( area4 );
stack->setCurrentIndex( 0 );
// QLabel *test = new QLabel(this);
// test->setPixmap(QPixmap::fromImage(QImage(":/images/splash0.jpg")));
}
void mainPage::loadSplashes() {
area0->setPixmap( QPixmap::fromImage( QImage( ":images/splash0.jpg" ) ) );
area1->setPixmap( QPixmap::fromImage( QImage( ":images/splash1.jpg" ) ) );
area2->setPixmap( QPixmap::fromImage( QImage( ":images/splash2.jpg" ) ) );
area3->setPixmap( QPixmap::fromImage( QImage( ":images/splash3.jpg" ) ) );
area4->setPixmap( QPixmap::fromImage( QImage( ":images/splash4.jpg" ) ) );
}
void mainPage::showContent( QAction* action ) {
qDebug() << "showContent called: " << action->objectName();
if ( action->objectName() == "action_Show_Main" ) {
stack->setCurrentIndex( 0 );
} else if ( action->objectName() == "action_Show_Photos" ) {
stack->setCurrentIndex( 1 );
} else if ( action->objectName() == "action_Show_Movies" ) {
stack->setCurrentIndex( 2 );
} else if ( action->objectName() == "action_Show_Games" ) {
stack->setCurrentIndex( 3 );
} else if ( action->objectName() == "action_Show_Tools" ) {
stack->setCurrentIndex( 4 );
} else {
stack->setCurrentIndex( 0 );
}
}Why that? it's set up exactly like the central Widget.