QMessageBox, Scrollarea und Bild einfügen
-
Hallo zusammen,
ich arbeite gerade an einem kleinen, meinem ersten, Projekt mit Qt.
Ich möchte nun eine QMessageBox, die Scrollbar ist und dann noch ein Bild einfügen.
Dank eines Snippets, welches ich irgendwo gefunden habe, ist das Problem mit der Scrollarea bereits gelöst.Auch das anzeigen eines Bildes Funktioniert. Nur leider auf dem falschen Form...
Hier mal etwas Code, was ich bereits habe....
Hier die scrollmessagebox.h
#ifndef SCROLLMESSAGEBOX_H #define SCROLLMESSAGEBOX_H #include <QScrollArea> #include <QDialog> #include <QDialogButtonBox> #include <QLabel> #include <QMessageBox> #include <QString> #include <QLayout> #include <QStyle> #include <QApplication> #include <QPushButton> #include <QDesktopWidget> #include <QGuiApplication> #include <QScreen> #include <QFontMetrics> //#pragma once // ScrollMessageBox // This class is just like QMessageBox, the only difference is that we put the displayed // text inside a scroll area so that longer messages can be shown. class ScrollMessageBox : public QDialog { Q_OBJECT public: ScrollMessageBox(QMessageBox::Icon icon, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok, QWidget* parent = 0); void setDefaultButton(QDialogButtonBox::StandardButton button); static QDialogButtonBox::StandardButton critical(QWidget* parent, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok, QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::NoButton); static QDialogButtonBox::StandardButton information(QWidget* parent, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok, QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::NoButton); static QDialogButtonBox::StandardButton question(QWidget* parent, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok, QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::NoButton); static QDialogButtonBox::StandardButton warning(QWidget* parent, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok, QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::NoButton); void showEvent ( QShowEvent * event ) override; private: QPixmap standardIcon(QMessageBox::Icon icon); void setDefaultButton(QPushButton *button); void updateSize(); QLabel *label; QDialogButtonBox *buttonBox; private Q_SLOTS: void handle_buttonClicked(QAbstractButton *button); }; #endif // SCROLLMESSAGEBOX_H
Hier die scrollmessagebox.cpp
#include "scrollmessagebox.h" ScrollMessageBox::ScrollMessageBox(QMessageBox::Icon icon, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons /*= QDialogButtonBox::Ok*/, QWidget* parent /*= 0*/) : QDialog(parent, Qt::Dialog | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint) { QLabel *iconLabel; QScrollArea *scroll; label = new QLabel; label->setTextInteractionFlags(Qt::TextInteractionFlags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this))); label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); label->setOpenExternalLinks(true); label->setContentsMargins(2, 0, 0, 0); label->setIndent(9); scroll = new QScrollArea(this); scroll->setGeometry(QRect(10, 20, 560, 430)); scroll->setWidget(label); scroll->setWidgetResizable(true); iconLabel = new QLabel; iconLabel->setPixmap(standardIcon((QMessageBox::Icon)icon)); iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); buttonBox = new QDialogButtonBox(buttons); buttonBox->setCenterButtons(style()->styleHint(QStyle::SH_MessageBox_CenterButtons, 0, this)); QObject::connect(buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(handle_buttonClicked(QAbstractButton*))); QGridLayout *grid = new QGridLayout; grid->addWidget(iconLabel, 0, 0, 2, 1, Qt::AlignTop); grid->addWidget(scroll, 0, 1, 1, 1); grid->addWidget(buttonBox, 1, 0, 1, 2); grid->setSizeConstraint(QLayout::SetNoConstraint); setLayout(grid); if (!title.isEmpty() || !text.isEmpty()) { setWindowTitle(title); label->setText(text); } setModal(true); } QPixmap ScrollMessageBox::standardIcon(QMessageBox::Icon icon) { QStyle *style = this->style(); int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, this); QIcon tmpIcon; switch (icon) { case QMessageBox::Information: tmpIcon = style->standardIcon(QStyle::SP_MessageBoxInformation, 0, this); break; case QMessageBox::Warning: tmpIcon = style->standardIcon(QStyle::SP_MessageBoxWarning, 0, this); break; case QMessageBox::Critical: tmpIcon = style->standardIcon(QStyle::SP_MessageBoxCritical, 0, this); break; case QMessageBox::Question: tmpIcon = style->standardIcon(QStyle::SP_MessageBoxQuestion, 0, this); default: break; } if (!tmpIcon.isNull()) { return tmpIcon.pixmap(iconSize, iconSize); } return QPixmap(); } void ScrollMessageBox::handle_buttonClicked(QAbstractButton *button) { int ret = buttonBox->standardButton(button); done(ret); } void ScrollMessageBox::setDefaultButton(QPushButton *button) { if (!buttonBox->buttons().contains(button)) return; button->setDefault(true); button->setFocus(); } void ScrollMessageBox::setDefaultButton(QDialogButtonBox::StandardButton button) { setDefaultButton(buttonBox->button(button)); } void ScrollMessageBox::showEvent(QShowEvent *e) { resize(800, 600); // width, height //updateSize(); QDialog::showEvent(e); } void ScrollMessageBox::updateSize() { if (!isVisible()) return; QScreen *screenSize = QGuiApplication::primaryScreen(); QRect screenGeometry = screenSize->geometry(); const int screenWidth = screenGeometry.width(); const int screenHeight = screenGeometry.height(); const int windowWidth = QWidget::width(); const int windowHeight = QWidget::height(); int hardLimit_width = qMin(screenWidth - 200 /*480*/, 1000); // can never get bigger than this // on small screens allows the messagebox be the same size as the screen if (screenWidth <= 1024) hardLimit_width = screenWidth; layout()->activate(); int widthBox = layout()->totalMinimumSize().width(); { int windowTitleWidth = qMin(windowWidth + 50, hardLimit_width); if (windowTitleWidth > widthBox) widthBox = windowTitleWidth; } int hardLimit_height = qMin(screenHeight - 250, 1000); // can never get bigger than this int heightBox; { heightBox = qMin(windowHeight - 50, hardLimit_height); } resize(widthBox, heightBox); } QDialogButtonBox::StandardButton ScrollMessageBox::critical(QWidget* parent, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons, QDialogButtonBox::StandardButton defaultButton) { ScrollMessageBox box(QMessageBox::Critical, title, text, buttons, parent); box.setDefaultButton(defaultButton); return static_cast<QDialogButtonBox::StandardButton>(box.exec()); } QDialogButtonBox::StandardButton ScrollMessageBox::information(QWidget* parent, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons, QDialogButtonBox::StandardButton defaultButton) { ScrollMessageBox box(QMessageBox::Information, title, text, buttons, parent); box.setDefaultButton(defaultButton); return static_cast<QDialogButtonBox::StandardButton>(box.exec()); } QDialogButtonBox::StandardButton ScrollMessageBox::question(QWidget* parent, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons, QDialogButtonBox::StandardButton defaultButton) { ScrollMessageBox box(QMessageBox::Question, title, text, buttons, parent); box.setDefaultButton(defaultButton); return static_cast<QDialogButtonBox::StandardButton>(box.exec()); } QDialogButtonBox::StandardButton ScrollMessageBox::warning(QWidget* parent, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons, QDialogButtonBox::StandardButton defaultButton) { ScrollMessageBox box(QMessageBox::Warning, title, text, buttons, parent); box.setDefaultButton(defaultButton); return static_cast<QDialogButtonBox::StandardButton>(box.exec()); }
Und hier ein Teil der cpp, aus der ich das aufrufe:
QGridLayout *layout = new QGridLayout(this);; QImage resoImage; resoImage.load("./Bilder/Resobirne.jpg"); QLabel* imageLabel; imageLabel = new QLabel(); imageLabel->setObjectName("showImage"); imageLabel->setPixmap(QPixmap::fromImage(resoImage)); layout->addWidget(imageLabel); imageLabel->show(); ScrollMessageBox::information(this, title, message, QDialogButtonBox::Ok, QDialogButtonBox::NoButton);
Wie gesagt, das Bild erscheint nicht in der MessageBox sondern auf dem Form von dem ich es aufrufe...
Komme da gerade nicht weiter, wäre super, wenn mir da jemand etwas helfen könnte.VG
Matze -
Hallo zusammen,
ich arbeite gerade an einem kleinen, meinem ersten, Projekt mit Qt.
Ich möchte nun eine QMessageBox, die Scrollbar ist und dann noch ein Bild einfügen.
Dank eines Snippets, welches ich irgendwo gefunden habe, ist das Problem mit der Scrollarea bereits gelöst.Auch das anzeigen eines Bildes Funktioniert. Nur leider auf dem falschen Form...
Hier mal etwas Code, was ich bereits habe....
Hier die scrollmessagebox.h
#ifndef SCROLLMESSAGEBOX_H #define SCROLLMESSAGEBOX_H #include <QScrollArea> #include <QDialog> #include <QDialogButtonBox> #include <QLabel> #include <QMessageBox> #include <QString> #include <QLayout> #include <QStyle> #include <QApplication> #include <QPushButton> #include <QDesktopWidget> #include <QGuiApplication> #include <QScreen> #include <QFontMetrics> //#pragma once // ScrollMessageBox // This class is just like QMessageBox, the only difference is that we put the displayed // text inside a scroll area so that longer messages can be shown. class ScrollMessageBox : public QDialog { Q_OBJECT public: ScrollMessageBox(QMessageBox::Icon icon, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok, QWidget* parent = 0); void setDefaultButton(QDialogButtonBox::StandardButton button); static QDialogButtonBox::StandardButton critical(QWidget* parent, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok, QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::NoButton); static QDialogButtonBox::StandardButton information(QWidget* parent, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok, QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::NoButton); static QDialogButtonBox::StandardButton question(QWidget* parent, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok, QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::NoButton); static QDialogButtonBox::StandardButton warning(QWidget* parent, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok, QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::NoButton); void showEvent ( QShowEvent * event ) override; private: QPixmap standardIcon(QMessageBox::Icon icon); void setDefaultButton(QPushButton *button); void updateSize(); QLabel *label; QDialogButtonBox *buttonBox; private Q_SLOTS: void handle_buttonClicked(QAbstractButton *button); }; #endif // SCROLLMESSAGEBOX_H
Hier die scrollmessagebox.cpp
#include "scrollmessagebox.h" ScrollMessageBox::ScrollMessageBox(QMessageBox::Icon icon, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons /*= QDialogButtonBox::Ok*/, QWidget* parent /*= 0*/) : QDialog(parent, Qt::Dialog | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint) { QLabel *iconLabel; QScrollArea *scroll; label = new QLabel; label->setTextInteractionFlags(Qt::TextInteractionFlags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this))); label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); label->setOpenExternalLinks(true); label->setContentsMargins(2, 0, 0, 0); label->setIndent(9); scroll = new QScrollArea(this); scroll->setGeometry(QRect(10, 20, 560, 430)); scroll->setWidget(label); scroll->setWidgetResizable(true); iconLabel = new QLabel; iconLabel->setPixmap(standardIcon((QMessageBox::Icon)icon)); iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); buttonBox = new QDialogButtonBox(buttons); buttonBox->setCenterButtons(style()->styleHint(QStyle::SH_MessageBox_CenterButtons, 0, this)); QObject::connect(buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(handle_buttonClicked(QAbstractButton*))); QGridLayout *grid = new QGridLayout; grid->addWidget(iconLabel, 0, 0, 2, 1, Qt::AlignTop); grid->addWidget(scroll, 0, 1, 1, 1); grid->addWidget(buttonBox, 1, 0, 1, 2); grid->setSizeConstraint(QLayout::SetNoConstraint); setLayout(grid); if (!title.isEmpty() || !text.isEmpty()) { setWindowTitle(title); label->setText(text); } setModal(true); } QPixmap ScrollMessageBox::standardIcon(QMessageBox::Icon icon) { QStyle *style = this->style(); int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, this); QIcon tmpIcon; switch (icon) { case QMessageBox::Information: tmpIcon = style->standardIcon(QStyle::SP_MessageBoxInformation, 0, this); break; case QMessageBox::Warning: tmpIcon = style->standardIcon(QStyle::SP_MessageBoxWarning, 0, this); break; case QMessageBox::Critical: tmpIcon = style->standardIcon(QStyle::SP_MessageBoxCritical, 0, this); break; case QMessageBox::Question: tmpIcon = style->standardIcon(QStyle::SP_MessageBoxQuestion, 0, this); default: break; } if (!tmpIcon.isNull()) { return tmpIcon.pixmap(iconSize, iconSize); } return QPixmap(); } void ScrollMessageBox::handle_buttonClicked(QAbstractButton *button) { int ret = buttonBox->standardButton(button); done(ret); } void ScrollMessageBox::setDefaultButton(QPushButton *button) { if (!buttonBox->buttons().contains(button)) return; button->setDefault(true); button->setFocus(); } void ScrollMessageBox::setDefaultButton(QDialogButtonBox::StandardButton button) { setDefaultButton(buttonBox->button(button)); } void ScrollMessageBox::showEvent(QShowEvent *e) { resize(800, 600); // width, height //updateSize(); QDialog::showEvent(e); } void ScrollMessageBox::updateSize() { if (!isVisible()) return; QScreen *screenSize = QGuiApplication::primaryScreen(); QRect screenGeometry = screenSize->geometry(); const int screenWidth = screenGeometry.width(); const int screenHeight = screenGeometry.height(); const int windowWidth = QWidget::width(); const int windowHeight = QWidget::height(); int hardLimit_width = qMin(screenWidth - 200 /*480*/, 1000); // can never get bigger than this // on small screens allows the messagebox be the same size as the screen if (screenWidth <= 1024) hardLimit_width = screenWidth; layout()->activate(); int widthBox = layout()->totalMinimumSize().width(); { int windowTitleWidth = qMin(windowWidth + 50, hardLimit_width); if (windowTitleWidth > widthBox) widthBox = windowTitleWidth; } int hardLimit_height = qMin(screenHeight - 250, 1000); // can never get bigger than this int heightBox; { heightBox = qMin(windowHeight - 50, hardLimit_height); } resize(widthBox, heightBox); } QDialogButtonBox::StandardButton ScrollMessageBox::critical(QWidget* parent, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons, QDialogButtonBox::StandardButton defaultButton) { ScrollMessageBox box(QMessageBox::Critical, title, text, buttons, parent); box.setDefaultButton(defaultButton); return static_cast<QDialogButtonBox::StandardButton>(box.exec()); } QDialogButtonBox::StandardButton ScrollMessageBox::information(QWidget* parent, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons, QDialogButtonBox::StandardButton defaultButton) { ScrollMessageBox box(QMessageBox::Information, title, text, buttons, parent); box.setDefaultButton(defaultButton); return static_cast<QDialogButtonBox::StandardButton>(box.exec()); } QDialogButtonBox::StandardButton ScrollMessageBox::question(QWidget* parent, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons, QDialogButtonBox::StandardButton defaultButton) { ScrollMessageBox box(QMessageBox::Question, title, text, buttons, parent); box.setDefaultButton(defaultButton); return static_cast<QDialogButtonBox::StandardButton>(box.exec()); } QDialogButtonBox::StandardButton ScrollMessageBox::warning(QWidget* parent, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons, QDialogButtonBox::StandardButton defaultButton) { ScrollMessageBox box(QMessageBox::Warning, title, text, buttons, parent); box.setDefaultButton(defaultButton); return static_cast<QDialogButtonBox::StandardButton>(box.exec()); }
Und hier ein Teil der cpp, aus der ich das aufrufe:
QGridLayout *layout = new QGridLayout(this);; QImage resoImage; resoImage.load("./Bilder/Resobirne.jpg"); QLabel* imageLabel; imageLabel = new QLabel(); imageLabel->setObjectName("showImage"); imageLabel->setPixmap(QPixmap::fromImage(resoImage)); layout->addWidget(imageLabel); imageLabel->show(); ScrollMessageBox::information(this, title, message, QDialogButtonBox::Ok, QDialogButtonBox::NoButton);
Wie gesagt, das Bild erscheint nicht in der MessageBox sondern auf dem Form von dem ich es aufrufe...
Komme da gerade nicht weiter, wäre super, wenn mir da jemand etwas helfen könnte.VG
Matze@MHage said in QMessageBox, Scrollarea und Bild einfügen:
Und hier ein Teil der cpp, aus der ich das aufrufe:
QGridLayout *layout = new QGridLayout(this); QLabel* imageLabel; imageLabel->setPixmap(QPixmap::fromImage(resoImage)); layout->addWidget(imageLabel);
Wie gesagt, das Bild erscheint nicht in der MessageBox sondern auf dem Form von dem ich es aufrufe...
QGridLayout *layout = new QGridLayout(this);
=> DieQGridLayout
(mitimageLabel
) erscheint aufthis
. Wie sollt das auf der MessageBox erscheinen?In
ScrollMessageBox::ScrollMessageBox()
haben Sie:QLabel *iconLabel; iconLabel = new QLabel; QGridLayout *grid = new QGridLayout; grid->addWidget(iconLabel, 0, 0, 2, 1, Qt::AlignTop); setLayout(grid);
Vielleicht moechten Sie von
imageLabel->setPixmap(QPixmap::fromImage(resoImage));
dieimageLabel
als "Parameter zuScrollMessageBox::ScrollMessageBox()
ubergeben", ich weiss nicht wenn das Ihrer Ziel ist? -
Vielen Dank für die Antwort!
ich denke eher so: Habe resoImage als Zeiger übergeben
label = new QLabel; label->setTextInteractionFlags(Qt::TextInteractionFlags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this))); label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); label->setOpenExternalLinks(true); label->setContentsMargins(2, 0, 0, 0); label->setIndent(9); label->setPixmap(QPixmap::fromImage(const QImage &resoImage));
denn ich möchte das Bild innerhalb der ScollArea haben.
Leider funktioniert das so nicht , denn ich bekomme folgenden Fehler, den ich gerade nicht zuordnen kann.scrollmessagebox.cpp:17: Fehler: expected primary-expression before ‘const’ scrollmessagebox.cpp:17:39: error: expected primary-expression before ‘const’ 17 | label->setPixmap(QPixmap::fromImage(const QImage &resoImage)); | ^~~~~
Ich sehe gerade den Fehler nicht...
-
Vielen Dank für die Antwort!
ich denke eher so: Habe resoImage als Zeiger übergeben
label = new QLabel; label->setTextInteractionFlags(Qt::TextInteractionFlags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this))); label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); label->setOpenExternalLinks(true); label->setContentsMargins(2, 0, 0, 0); label->setIndent(9); label->setPixmap(QPixmap::fromImage(const QImage &resoImage));
denn ich möchte das Bild innerhalb der ScollArea haben.
Leider funktioniert das so nicht , denn ich bekomme folgenden Fehler, den ich gerade nicht zuordnen kann.scrollmessagebox.cpp:17: Fehler: expected primary-expression before ‘const’ scrollmessagebox.cpp:17:39: error: expected primary-expression before ‘const’ 17 | label->setPixmap(QPixmap::fromImage(const QImage &resoImage)); | ^~~~~
Ich sehe gerade den Fehler nicht...
@MHage said in QMessageBox, Scrollarea und Bild einfügen:
label->setPixmap(QPixmap::fromImage(const QImage &resoImage));
Nicht legal C++. Muesst sein:
label->setPixmap(QPixmap::fromImage(resoImage));
Wo ist Ihrer
QImage resoImage
?Habe resoImage als Zeiger übergeben
Zeigen Sie mir wie das in
ScrollMessageBox
ankommt? -
@JonB said in QMessageBox, Scrollarea und Bild einfügen:
setPixmap(QPixmap::fromImage(resoImage));
folgendes steht in der scrollmessagebox.cpp
label = new QLabel; label->setTextInteractionFlags(Qt::TextInteractionFlags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this))); label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); label->setOpenExternalLinks(true); label->setContentsMargins(2, 0, 0, 0); label->setIndent(9); label->setPixmap(QPixmap::fromImage(resoImage));
Dort habe ich jetzt übrigens folgenden Fehler:
scrollmessagebox.cpp:17: Fehler: no matching function for call to ‘QPixmap::fromImage(QImage*&)’ scrollmessagebox.cpp:17:48: error: no matching function for call to ‘QPixmap::fromImage(QImage*&)’ 17 | label->setPixmap(QPixmap::fromImage(resoImage)); | ^
Beim Aufruf steht jetzt nur noch dieses:
QImage* resoImage = new QImage(); resoImage->load("./Bilder/Resobirne.jpg"); ScrollMessageBox::information(this, title, message, QDialogButtonBox::Ok, QDialogButtonBox::NoButton, resoImage);
Leider kann ich das wegen dem Fehler nicht kompilieren.
Ich weiß also gerade auch nicht, was dort ankommt. -
@JonB said in QMessageBox, Scrollarea und Bild einfügen:
setPixmap(QPixmap::fromImage(resoImage));
folgendes steht in der scrollmessagebox.cpp
label = new QLabel; label->setTextInteractionFlags(Qt::TextInteractionFlags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this))); label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); label->setOpenExternalLinks(true); label->setContentsMargins(2, 0, 0, 0); label->setIndent(9); label->setPixmap(QPixmap::fromImage(resoImage));
Dort habe ich jetzt übrigens folgenden Fehler:
scrollmessagebox.cpp:17: Fehler: no matching function for call to ‘QPixmap::fromImage(QImage*&)’ scrollmessagebox.cpp:17:48: error: no matching function for call to ‘QPixmap::fromImage(QImage*&)’ 17 | label->setPixmap(QPixmap::fromImage(resoImage)); | ^
Beim Aufruf steht jetzt nur noch dieses:
QImage* resoImage = new QImage(); resoImage->load("./Bilder/Resobirne.jpg"); ScrollMessageBox::information(this, title, message, QDialogButtonBox::Ok, QDialogButtonBox::NoButton, resoImage);
Leider kann ich das wegen dem Fehler nicht kompilieren.
Ich weiß also gerade auch nicht, was dort ankommt. -
Ich habe das jetzt mal so abgeändert:
scrollmessagebox.cpp
ScrollMessageBox::ScrollMessageBox(QMessageBox::Icon icon, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons /*= QDialogButtonBox::Ok*/, QWidget* parent /*= 0*/, QImage* resoImage) : QDialog(parent, Qt::Dialog | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint) { QWidget* container = new QWidget(this); QVBoxLayout * layout = new QVBoxLayout(container); QLabel* imageLabel = new QLabel(container); QLabel* label = new QLabel(container); layout->addWidget(imageLabel); layout->addWidget(label); QLabel* iconLabel = new QLabel; QScrollArea *scroll = new QScrollArea(this); label->setTextInteractionFlags(Qt::TextInteractionFlags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this))); label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); label->setOpenExternalLinks(true); label->setContentsMargins(2, 0, 0, 0); label->setIndent(9); scroll->setGeometry(QRect(10, 20, 560, 430)); scroll->setWidget(container); scroll->setWidgetResizable(true); iconLabel->setPixmap(standardIcon((QMessageBox::Icon)icon)); iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); buttonBox = new QDialogButtonBox(buttons); buttonBox->setCenterButtons(style()->styleHint(QStyle::SH_MessageBox_CenterButtons, 0, this)); QObject::connect(buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(handle_buttonClicked(QAbstractButton*))); QGridLayout *grid = new QGridLayout; grid->addWidget(iconLabel, 0, 0, 2, 1, Qt::AlignTop); grid->addWidget(scroll, 0, 1, 1, 1); grid->addWidget(buttonBox, 1, 0, 1, 2); grid->setSizeConstraint(QLayout::SetNoConstraint); setLayout(grid); if (!title.isEmpty() || !text.isEmpty()) { setWindowTitle(title); label->setPixmap(QPixmap::fromImage(*resoImage)); label->setText(text); } setModal(true); }
Bild wird immer noch nicht angezeigt. Verstehe ich gerade auch nicht...
-
Ich habe das jetzt mal so abgeändert:
scrollmessagebox.cpp
ScrollMessageBox::ScrollMessageBox(QMessageBox::Icon icon, QString const& title, QString const& text, QDialogButtonBox::StandardButtons buttons /*= QDialogButtonBox::Ok*/, QWidget* parent /*= 0*/, QImage* resoImage) : QDialog(parent, Qt::Dialog | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint) { QWidget* container = new QWidget(this); QVBoxLayout * layout = new QVBoxLayout(container); QLabel* imageLabel = new QLabel(container); QLabel* label = new QLabel(container); layout->addWidget(imageLabel); layout->addWidget(label); QLabel* iconLabel = new QLabel; QScrollArea *scroll = new QScrollArea(this); label->setTextInteractionFlags(Qt::TextInteractionFlags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this))); label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); label->setOpenExternalLinks(true); label->setContentsMargins(2, 0, 0, 0); label->setIndent(9); scroll->setGeometry(QRect(10, 20, 560, 430)); scroll->setWidget(container); scroll->setWidgetResizable(true); iconLabel->setPixmap(standardIcon((QMessageBox::Icon)icon)); iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); buttonBox = new QDialogButtonBox(buttons); buttonBox->setCenterButtons(style()->styleHint(QStyle::SH_MessageBox_CenterButtons, 0, this)); QObject::connect(buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(handle_buttonClicked(QAbstractButton*))); QGridLayout *grid = new QGridLayout; grid->addWidget(iconLabel, 0, 0, 2, 1, Qt::AlignTop); grid->addWidget(scroll, 0, 1, 1, 1); grid->addWidget(buttonBox, 1, 0, 1, 2); grid->setSizeConstraint(QLayout::SetNoConstraint); setLayout(grid); if (!title.isEmpty() || !text.isEmpty()) { setWindowTitle(title); label->setPixmap(QPixmap::fromImage(*resoImage)); label->setText(text); } setModal(true); }
Bild wird immer noch nicht angezeigt. Verstehe ich gerade auch nicht...
-
Verstehe ich doch ....
Hab noch eine Kleinigkeit angepasst.
label->setPixmap(QPixmap::fromImage(*resoImage));
muss schon so aussehen:
imageLabel->setPixmap(QPixmap::fromImage(*resoImage));
Vielen Dank für die Unterstützung!
Jetzt muss noch schauen, ob ich das Bild noch etwas positionieren kann