标题:如何改变按钮及其字体的颜色
作者:polarity
日期:2006-09-20 11:25
内容:
我想改变默认的按钮颜色和按钮上字体的颜色,我用的是qt2.3.7,请问能实现么
我尝试了一下uclinux发的改变按钮字体颜色的方法
QPushButton pushbutton("hello world");
.......
.......
.......
QPalette newPalette = pushbutton.palette();
newPalette.setColor(QPalette::ButtonText, Qt::blue);
pushButton.setPalette(newPalette);
但是编译时提示没有ButtonText成员:(
#1 [style 09-20 16:28]
QPushButton pushbutton("hello world");
.......
.......
.......
QColor newColor = ("blue");
QColorGroup new = palette().copy().normal();
new.setColor(ColorGroup::ButtonText, QColor("blue"));
QPalette newp;
newp.setNormal(new);
setPlalette(newPalette.true);
#2 [polarity 09-20 18:02]
我按你的方法敲进去了,出现了语法错误
QColorGroup new = palette().copy().normal();和 newp.setNormal(new);
还有 setPalette(newp,true);这三句有问题
#3 [style 09-20 20:05]
我写的是QT3的.
我没QT2文档.所以不知道相关函数名和参数.
我只是大概意思.你看懂我的这段代码意思就行了.最主要是你写的代码思路就不对.
QPalette::ButtonText
QPalette分4种模式, (QT4中,好像在QT3中只分3种)
QPalette::Disabled
QPalette::Active
QPalette::Inactive
QPalette::Normal
而你写的ButtonText是QColorGroup的emun成员
#4 [style 09-20 20:06]
emun->enum
#5 [polarity 09-20 20:40]
谢谢style,不过我刚学习qt没多久不太会查文档,你写的语句我有些看不懂,比如QColorGroup new = palette().copy().normal(); newp.setNormal(new); setPlalette(newPalette.true);我现在只能照着现有的例程编点软件呵呵。麻烦你给我详细解释下好么,谢谢你
我把QPalette.h贴出来吧
/****************************************************************************
** $Id: qt/src/kernel/qpalette.h 2.3.7 edited 2001-05-08 $
**
** Definition of QColorGroup and QPalette classes
**
** Created : 950323
**
** Copyright (C) 1992-2000 Trolltech AS.All rights reserved.
**
** This file is part of the kernel module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
** licenses may use this file in accordance with the Qt Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
** information about Qt Commercial License Agreements.
** See http://www.trolltech.com/qpl/ for QPL licensing information.
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef QPALETTE_H
#define QPALETTE_H
#ifndef QT_H
#includ ..