[Qt-interest] Problem in multi QLabel & QGridLayout

Pradeep K V pradeep.vijayan at gmail.com
Mon Feb 23 16:12:23 CET 2009


Hello,

There can be only one central Widget at a time. In your case 
"setCentralWidget(imageLabel2);" replaces imageLabel.

Try this in your code:

     QWidget *mainWidget = new QWidget( this );
     setCentralWidget( mainWidget );
     QGridLayout *multilayout = new QGridLayout( mainWidget );
     <Rest of your code. Remove other setCentralWidget and setLayout 
function calls>

More info: http://doc.trolltech.com/4.4/qmainwindow.html#details

Hope it helps.
Pradeep

Ravi_Kalepalli wrote:
> Hi
> 
>             I am trying to display 2 images with QLabel. But it is 
> always displaying second image only ( book.bmp in my case).
> 
>             The first image getting overlapped by the second (I think)
> 
>             Could anybody help in this?
> 
>  
> 
> *Code:*
> 
>            
> 
> QGridLayout *multiLayout = *new* *QGridLayout*(*this*);
> 
>            
> 
>             imageLabel = *new* *QLabel*(*this*);
> 
>             imageLabel->*setBackgroundRole*(QPalette::/Base/);
> 
>             imageLabel->*setSizePolicy*(QSizePolicy::/Ignored/, 
> QSizePolicy::/Ignored/);
> 
>             imageLabel->*setScaledContents*(*true*);
> 
>             *setCentralWidget*(imageLabel);
> 
>                        
> 
>             imageLabel2 = *new* *QLabel*(*this*);
> 
>             imageLabel2->*setBackgroundRole*(QPalette::/Base/);
> 
>             imageLabel2->*setSizePolicy*(QSizePolicy::/Ignored/, 
> QSizePolicy::/Ignored/);
> 
>             imageLabel2->*setScaledContents*(*true*);
> 
>             *setCentralWidget*(imageLabel2);
> 
>            
> 
>             multiLayout->*addWidget*(imageLabel,0,0);
> 
>             multiLayout->*addWidget*(imageLabel2,1,1);
> 
>            
> 
>            
> 
>             QString NextImagepath = 
> "c:\\Data\\Images\\Pictures\\battery.jpg";
> 
>             QPixmap Nextimage(NextImagepath);
> 
>             imageLabel->*setPixmap*(Nextimage);
> 
>  
> 
>             QString NextImagepath2 = "c:\\Data\\Images\\Pictures\\ 
> book.bmp";
> 
>             QPixmap Nextimage2(NextImagepath2);
> 
>             imageLabel2->*setPixmap*(Nextimage2);
> 
>  
> 
>             *setLayout*(multiLayout);
> 
>  
> 
>  
> 
> Thanks and Regards
> 
>  
> 
> Ravi Kalepalli
> 
> Telephone: 080-66577808
> 
> Mobile: 9880724688
> 
>  
> 
> 
> ------------------------------------------------------------------------
> DISCLAIMER:
> This email (including any attachments) is intended for the sole use of 
> the intended recipient/s and may contain material that is CONFIDENTIAL 
> AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or 
> copying or distribution or forwarding of any or all of the contents in 
> this message is STRICTLY PROHIBITED. If you are not the intended 
> recipient, please contact the sender by email and delete all copies; 
> your cooperation in this regard is appreciated.

-- 
Pradeep K V
Bugless Software Development Ltd.
https://bugless.co.uk/



More information about the Qt-interest-old mailing list