Das folgende Programm funktioniert bei mir so wie ich es erwarten würde:
Code:
#include "QtCore/QObject"
#include "QtGui/QApplication"
#include "QtGui/QLabel"
#include "QtGui/QPixmap"
#include "QtGui/QPushButton"
#include "QtGui/QWidget"
class mainwindow : public QWidget
{
Q_OBJECT
public:
mainwindow() : label("Text Text ABC", this), button("Save pixmap to file and quit!", this) {
label.resize(400, 300);
button.move(0, 300);
QObject::connect(&button, SIGNAL(clicked()), this, SLOT(save_file()));
QObject::connect(&button, SIGNAL(clicked()), qApp, SLOT(quit()));
}
public slots:
void save_file() {
QPixmap pix(label.size());
label.render(&pix);
pix.save("save_label.output.bmp");
}
private:
QLabel label;
QPushButton button;
};
int main( int argc, char *argv[] ) {
QApplication app(argc, argv);
mainwindow app_window;
app_window.show();
return app.exec();
}
Lesezeichen