qt3->qt4 - QLabel-expanding geht nicht

Alles rund um die Programmierung mit Qt
Antworten
doitux
Beiträge: 12
Registriert: 21. September 2004 08:15

qt3->qt4 - QLabel-expanding geht nicht

Beitrag von doitux »

Hallo

Ich habe hier seit einem qt4-port ein Layout-Problem. Der gleiche QDialog hat sich in qt3 wie gewünscht verhalten. Ein Bild von dem "Problemkind" gibts im Anhang (gridlayout.png).
Eigentlich soll sich der QFrame und der QDialog vergrößern wenn das QLabel in der Mitte zu groß wird. Das ganze ist sowohl beim QFrame als auch beim QDialog im Gridlayout angeordnet. Ich hab bei QLabel, QFrame, und QDialog schon alle Einstellungen zur Sizepolicy probiert aber nichts hat geklappt. Oder ich hab einfach noch nicht die richtige Kombination verstanden.

Kann mit jemand einen Tip geben wie die Sizepolicy für QLabel, QFrame und QDialog aussehen müsste damit das klappt?

Vielen Dank
doitux

ps: Der ui-code aus dem designer sieht so

Code: Alles auswählen

#ifndef UI_QUPILBIRTHDAYREMINDER_H
#define UI_QUPILBIRTHDAYREMINDER_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QFrame>
#include <QtGui/QGridLayout>
#include <QtGui/QLabel>
#include <QtGui/QPushButton>

class Ui_qupilbirthdayreminder
{
public:
    QGridLayout *gridLayout;
    QFrame *frame;
    QGridLayout *gridLayout1;
    QLabel *textLabel3;
    QLabel *textLabel1;
    QLabel *textLabel2;
    QLabel *label;
    QPushButton *pushButton14;

    void setupUi(QDialog *qupilbirthdayreminder)
    {
    qupilbirthdayreminder->setObjectName(QString::fromUtf8("qupilbirthdayreminder"));
    qupilbirthdayreminder->resize(QSize(386, 216).expandedTo(qupilbirthdayreminder->minimumSizeHint()));
    QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(13), static_cast<QSizePolicy::Policy>(5));
    sizePolicy.setHorizontalStretch(0);
    sizePolicy.setVerticalStretch(0);
    sizePolicy.setHeightForWidth(qupilbirthdayreminder->sizePolicy().hasHeightForWidth());
    qupilbirthdayreminder->setSizePolicy(sizePolicy);
    qupilbirthdayreminder->setMinimumSize(QSize(300, 170));
    qupilbirthdayreminder->setSizeGripEnabled(false);
    gridLayout = new QGridLayout(qupilbirthdayreminder);
    gridLayout->setSpacing(6);
    gridLayout->setMargin(9);
    gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
    frame = new QFrame(qupilbirthdayreminder);
    frame->setObjectName(QString::fromUtf8("frame"));
    QSizePolicy sizePolicy1(static_cast<QSizePolicy::Policy>(13), static_cast<QSizePolicy::Policy>(5));
    sizePolicy1.setHorizontalStretch(0);
    sizePolicy1.setVerticalStretch(0);
    sizePolicy1.setHeightForWidth(frame->sizePolicy().hasHeightForWidth());
    frame->setSizePolicy(sizePolicy1);
    frame->setFrameShape(QFrame::StyledPanel);
    frame->setFrameShadow(QFrame::Raised);
    gridLayout1 = new QGridLayout(frame);
    gridLayout1->setSpacing(6);
    gridLayout1->setMargin(9);
    gridLayout1->setObjectName(QString::fromUtf8("gridLayout1"));
    textLabel3 = new QLabel(frame);
    textLabel3->setObjectName(QString::fromUtf8("textLabel3"));
    textLabel3->setMinimumSize(QSize(200, 0));

    gridLayout1->addWidget(textLabel3, 2, 1, 1, 1);

    textLabel1 = new QLabel(frame);
    textLabel1->setObjectName(QString::fromUtf8("textLabel1"));
    textLabel1->setMinimumSize(QSize(200, 0));

    gridLayout1->addWidget(textLabel1, 0, 1, 1, 1);

    textLabel2 = new QLabel(frame);
    textLabel2->setObjectName(QString::fromUtf8("textLabel2"));
    QSizePolicy sizePolicy2(static_cast<QSizePolicy::Policy>(13), static_cast<QSizePolicy::Policy>(5));
    sizePolicy2.setHorizontalStretch(0);
    sizePolicy2.setVerticalStretch(0);
    sizePolicy2.setHeightForWidth(textLabel2->sizePolicy().hasHeightForWidth());
    textLabel2->setSizePolicy(sizePolicy2);
    textLabel2->setAlignment(Qt::AlignCenter);
    textLabel2->setWordWrap(false);

    gridLayout1->addWidget(textLabel2, 1, 1, 1, 1);

    label = new QLabel(frame);
    label->setObjectName(QString::fromUtf8("label"));
    QSizePolicy sizePolicy3(static_cast<QSizePolicy::Policy>(0), static_cast<QSizePolicy::Policy>(0));
    sizePolicy3.setHorizontalStretch(0);
    sizePolicy3.setVerticalStretch(0);
    sizePolicy3.setHeightForWidth(label->sizePolicy().hasHeightForWidth());
    label->setSizePolicy(sizePolicy3);
    label->setMinimumSize(QSize(140, 140));
    label->setMaximumSize(QSize(140, 140));
    label->setPixmap(QPixmap(QString::fromUtf8(":/images/birthday.png")));
    label->setScaledContents(true);

    gridLayout1->addWidget(label, 0, 0, 3, 1);


    gridLayout->addWidget(frame, 0, 0, 1, 1);

    pushButton14 = new QPushButton(qupilbirthdayreminder);
    pushButton14->setObjectName(QString::fromUtf8("pushButton14"));

    gridLayout->addWidget(pushButton14, 1, 0, 1, 1);

    retranslateUi(qupilbirthdayreminder);

    QMetaObject::connectSlotsByName(qupilbirthdayreminder);
    } // setupUi

    void retranslateUi(QDialog *qupilbirthdayreminder)
    {
    qupilbirthdayreminder->setWindowTitle(QApplication::translate("qupilbirthdayreminder", "Qupil - Geburtstage", 0, QApplication::UnicodeUTF8));
    textLabel3->setText(QApplication::translate("qupilbirthdayreminder", "<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\" white-space: pre-wrap; font-family:Nimbus Sans L; font-size:8pt; font-weight:400; font-style:normal; text-decoration:none;\"><p align=\"center\" style=\" margin-top:16px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;\"><font size=\"5\">Geburtstag!</font></p></body></html>", 0, QApplication::UnicodeUTF8));
    textLabel1->setText(QApplication::translate("qupilbirthdayreminder", "<h2><p align=\"center\">Gestern hatte</p></h2>", 0, QApplication::UnicodeUTF8));
    textLabel2->setText(QApplication::translate("qupilbirthdayreminder", "<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\" white-space: pre-wrap; font-family:Nimbus Sans L; font-size:8pt; font-weight:400; font-style:normal; text-decoration:none;\"><p align=\"center\" style=\" margin-top:18px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;\"><font size=\"6\"><font size=\"6\">Sch\303\274ler</font></font></p></body></html>", 0, QApplication::UnicodeUTF8));
    label->setText(QApplication::translate("qupilbirthdayreminder", "", 0, QApplication::UnicodeUTF8));
    pushButton14->setText(QApplication::translate("qupilbirthdayreminder", "&OK", 0, QApplication::UnicodeUTF8));
    pushButton14->setShortcut(QApplication::translate("qupilbirthdayreminder", "Alt+O", 0, QApplication::UnicodeUTF8));
    Q_UNUSED(qupilbirthdayreminder);
    } // retranslateUi

};

namespace Ui {
    class qupilbirthdayreminder: public Ui_qupilbirthdayreminder {};
} // namespace Ui

#endif // UI_QUPILBIRTHDAYREMINDER_H
Dateianhänge
gridlayout.png
gridlayout.png (35.78 KiB) 2643 mal betrachtet
patrik08
Beiträge: 746
Registriert: 27. Februar 2006 10:48
Wohnort: DE Freiburg

Beitrag von patrik08 »

im ui .... muss es etwa so aussehen.....

minimum & maxium setzen und von expanding auf fixed....
dann ist es fest...

wenn nur bild.... wenn text drinnen ist .... mac gibt sie etwa 20% kleiner an....

Code: Alles auswählen


<widget class="QDialog" name="Gui_About" >
  <property name="geometry" >
   <rect>
    <x>0</x>
    <y>0</y>
    <width>502</width>
    <height>315</height>
   </rect>

<property name="minimumSize" >
   <size>
    <width>502</width>
    <height>315</height>
   </size>
  </property>
  <property name="maximumSize" >
   <size>
    <width>502</width>
    <height>315</height>
   </size>
  </property>
ArneStocker
Beiträge: 300
Registriert: 3. November 2004 16:15
Wohnort: Berlin

Beitrag von ArneStocker »

feste Werte haben aber den Nachteil, dass es Probleme auf einer Zielplattform mit abweichenden Schriftgrößen geben kann.

Versuchs doch mal mit

Code: Alles auswählen

pMyDialog = new ...
pMyDialog->adjustSize();
pMyDialog->exec();
vor dem Aufruf des Dialogs

Gruss Arne

PS.: Lösung ist allerdings auch aus Qt3.x, weiss daher nicht ob es auch mit Qt4.x funktioniert
PPS.: Da Du Deine Bildgrösse kennst, solltest Du für dieses Widget die min-und maxwerte fest auf die Pixelgrösse setzen
doitux
Beiträge: 12
Registriert: 21. September 2004 08:15

Beitrag von doitux »

Vielen Dank

mit pMyDialog->adjustSize(); tut es jetzt genauso wie unter qt3 früher. wurde bei qt3 adjustSize() standardmäßig bei exec() oder show() ausgeführt?

Gruß
doitux
Antworten