Я пытаюсь построить окно с графической сценой внутри: стопкой цветных прямоугольников (которые позже должны будут перемещаться).
Хотя я могу раскрашивать мои прямоугольники с Qt::green e. г. (также показано в scheibe.cpp:3, мне не удалось раскрасить их с помощью специального QColor. Кажется, только значение серого соответствует ожиданиям QColor. Есть совет?
Мой код
// main.cpp
#include
#include "fensterHaupt.h"
int main (int argc, char *argv []) {
QApplication app (argc, argv);
FensterHaupt fh (18, &app);
fh.show ();
return app.exec ();
}
// fensterHaupt.h
#ifndef FENSTERHAUPT_H
#define FENSTERHAUPT_H
#include
#include
#include
#include
#include
#include
#include
#include
#include "scheibe.h"
#include "ui_fensterHaupt.h"
class FensterHaupt : public QMainWindow {
Q_OBJECT
public :
FensterHaupt (int scheibenzahl, QApplication *vorfahr = 0);
Ui::FensterHaupt uiFensterHaupt;
QVBoxLayout *layout;
QGraphicsScene* szenenbild = new QGraphicsScene (this);
int scheibenzahl = 18;
QList farbpalette;
QList scheiben = {};
QColor farbeFestlegen (int scheibennr);
void spielfeldFullen ();
};
#endif // FENSTERHAUPT_H
// fensterHaupt.cpp
#include "fensterHaupt.h"
#include "ui_fensterHaupt.h"
FensterHaupt::FensterHaupt (int sz, QApplication *vorfahr) : scheibenzahl (sz) {
uiFensterHaupt.setupUi (this);
int grau = 0;
for (int v = 0; v setBrush (farben [scheibennr]); // taking colours here works
painter->setBrush (farbe); // taking colours here doesn't work (properly)
painter->drawRect (boundingRect () );
}
// fensterHaupt.ui
FensterHaupt
0
0
800
480
MainWindow
0
0
790
420
20
20
QAbstractScrollArea::AdjustToContents
Qt::AlignBottom|Qt::AlignHCenter
Подробнее здесь: https://stackoverflow.com/questions/793 ... -otherwise