Rand/Umrandung bei QGroupBox

Alles rund um die Programmierung mit Qt
Flachkoepper
Beiträge: 149
Registriert: 11. Januar 2005 12:14
Wohnort: Hannover

Beitrag von Flachkoepper »

Code: Alles auswählen

#include <QtGui>

int main( int argc, char ** argv )
{
    QApplication app( argc, argv );

QWidget* w = new QWidget;
	QGroupBox* gb = new QGroupBox(w);
	gb->setTitle("Hallo");

	QPalette p;
	p.setColor(QPalette::Window, QColor(Qt::red));
	p.setColor(QPalette::WindowText, QColor(Qt::green));
	gb->setPalette(p);

	w->show();
    app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
    return app.exec();
}
Kannst ja mal dein Projekt als zip hier posten, dann gucke ich mir das auch mal an.

Flachköpper
Maik
Beiträge: 45
Registriert: 29. Mai 2006 10:54

Beitrag von Maik »

hi, also so wie du es hast geht es.
hier ist mein bsp. code der nicht geht:

//main
#include "Widget_Main.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app( argc, argv );
Widget_Main Form1;
Form1.show();
return app.exec();
}
//----------------------------------------------------------------------
//Widget_Main.h
#ifndef WIDGET_MAIN_H
#define WIDGET_MAIN_H
#include <QtCore>
#include <QtGui>
class Widget_Main : public QWidget
{
Q_OBJECT
public:
Widget_Main( QWidget *parent = 0);
QGroupBox *box;
};
#endif
//--------------------------------------------------------------------
//Widget_Main.cpp
#include "Widget_Main.h"
Widget_Main::Widget_Main( QWidget *parent)
: QWidget (parent)
{
setObjectName("Widget_Main");
setFixedSize(1024, 777);

QPalette palette4;
palette4.setColor(QPalette::Window,QColor(Qt::red));
palette4.setColor(QPalette::WindowText,QColor(255,255,255));
palette4.setColor(QPalette::Dark, Qt::green);

QFont font4;
font4.setFamily("Sans Serif");
font4.setPointSize(12);
font4.setWeight(50);

box = new QGroupBox(this);
box->setObjectName("groupBox");
box->setGeometry(QRect(10, 10, 541, 231));
box->setPalette(palette4);
box->setFont(font4);
box->setTitle("Datenbytes");
box->setAutoFillBackground(true);
}
//----------------------------------------------------------------------------
kann es sein das es ein problem mit den parent(this) gibt?

danke
Flachkoepper
Beiträge: 149
Registriert: 11. Januar 2005 12:14
Wohnort: Hannover

Beitrag von Flachkoepper »

Aha, mach mal setAutoFillBackground(false).
Maik
Beiträge: 45
Registriert: 29. Mai 2006 10:54

Beitrag von Maik »

hey freunde, ich habs. es liet an groupBox->setAutoFillBackground(true);!
klinkt komisch...ist aber so :-)

falls mal ein anderer das problem hat

danke
Flachkoepper
Beiträge: 149
Registriert: 11. Januar 2005 12:14
Wohnort: Hannover

Beitrag von Flachkoepper »

Naja, komisch ist das nicht:
If enabled, this will cause Qt to fill the background using the widget's background role BEFORE invoking the paint event. The background role is defined by the widget's palette.
Also erstmal alles in einer Farbe überpinseln und dann erst das Widget zeichnen. Also konntest du deine Umrandung gar nicht sehen, da sie auch mit QPalette::Window gezeichnet wurde ;-)

Viele Grüße,
Flachkoepper
Antworten