Important: Please read the Qt Code of Conduct -

Problem in display while rotating my Qt Simulator

  • In Qt Simulator I have added four pushButton and an Image above it but when I am rotating my device all the things are not coming properly....I can only view image and one button below it in which the other three pushbuttons are not getting displayed...Please help me...

  • How did you determine the position of each widget? Are you using a layout?
    Post the relevant part of your code, so it'll be easier for us to help you :-)

  • @
    QLabel *lbl = new QLabel;
    QPixmap pixmap(QPixmap::fromImage(QImage(":/images/photos/nokia2.bmp")));

    videoButton = new QPushButton(tr("&VIDEO"));
    photoButton = new QPushButton(tr("&PHOTO"));
    radioButton = new QPushButton(tr("&RADIO"));
    newsButton = new QPushButton(tr("&NEWS"));

    QVBoxLayout *layout = new QVBoxLayout;


    [edit: fixed code tag / chetankjain]

  • Hi Prajnaranjan,

    Slight correction, its Qt and not QT (quick time)
    Also recommend enclosing code blocks with the @ tag, makes reading easier and Qt keywords are recognized

    the real estate available in portrait is different from the one in landscape, you will have to adjust your layout/component positions accordingly to make your UI look better.

  • Hi Prajnaranjan,

    I'm not how do You use your container widget (the one that holds label and all the buttons).
    I used QMainWindow inherited class and made it visible with showMaximized()
    In it's constructor i put your code (with modifications):

    QLabel *lbl = new QLabel;
    // i commented pixmap because i did not have an image...
    //QPixmap pixmap(QPixmap::fromImage(QImage(":/images/photos/nokia2.bmp")));
    // ... i used text insted
    lbl->setText("<Image goes here>");
    // lbl->alignment(); // this does nothing, it only returns current labels alignment, you don' need it here
    lbl->setAlignment(Qt::AlignCenter); // on the other hand this sets the alignment

    QPushButton* videoButton = new QPushButton(tr("&VIDEO"));
    //videoButton->show(); //you don't need to call this
    QPushButton* photoButton = new QPushButton(tr("&PHOTO"));
    //photoButton->show(); //you don't need to call this
    QPushButton* radioButton = new QPushButton(tr("&RADIO"));
    //radioButton->show(); //you don't need to call this
    QPushButton* newsButton = new QPushButton(tr("&NEWS"));
    //newsButton->show(); //you don't need to call this
    QWidget *centralWidget = new QWidget(this); // add a centralwidget to main window, it holds all the widgets displayed in MainWiwndow
    QVBoxLayout *layout = new QVBoxLayout;
        // You probably don't want the second and third parameter in addWidget()
        // second parameter is NOT row number where you insert your widget
        //layout->addWidget(lbl, 0, 0);
    centralWidget->setLayout(layout); //set layout on central widget, not on MainWindow


    This modified code works fine, all butons are visible and a label with text above them. Rotating in both orientations works fine as well.

    I just had a second thought about your problem. Maybe your buttons are not visible... because they come out of the screen because the image is too big?
    In that situation you should either make your image shrink or use QScrollArea as a central widget (it will show scroll bars when widgets get off the screen)

  • Its showing setCentralWidget was not diclared in this scope...
    How to fix it ....

  • [quote author="Prajnaranjan Das" date="1292220681"]Its showing setCentralWidget was not diclared in this scope...
    How to fix it ....[/quote]

    Prajnaranjan, I think you missed this part ...

    [quote author="JacquesBaniaque" date="1292064039"]...
    I used QMainWindow inherited class and made it visible with showMaximized()

Log in to reply