- Qt 4.5 QGroupBox with QGTkStyle
經jensbw前輩指導之後得知以下的效果原來是因為Qt 4.5為了要保留原生的Gnome的特效採用了QGtkStyle而造成的,並不是程式上得錯誤。而QGtkStyle則是Qt 4.5所強調的新功能之一,看來我真該好好去看一下這一篇What's New in Qt 4.5。
下面的截圖就是使用 Qt4.5去編譯Qt所提供的範例程式碼的樣子(在沒有更動任何程式碼的情況之下預設是使用QGtkStyle):
我們可以透過setStyle()的方法來指定想要的style,片段範例程式碼如下:
QGroupBox *gsGroupBox;
QGroupBox *clsGroupBox;
QCleanlooksStyle* clStyle;
void setupUi(QWidget *QDemoClass){
if (QDemoClass->objectName().isEmpty())
QDemoClass->setObjectName(QString::fromUtf8("QDemoClass"));
QDemoClass->resize(440, 178);
clStyle = new QCleanlooksStyle();
gsGroupBox = new QGroupBox(QDemoClass);
gsGroupBox->setObjectName(QString::fromUtf8("gsGroupBox"));
gsGroupBox->setGeometry(QRect(10, 10, 211, 161));
clsGroupBox = new QGroupBox(QDemoClass);
clsGroupBox->setObjectName(QString::fromUtf8("clsGroupBox"));
clsGroupBox->setGeometry(QRect(230, 10, 201, 161));
clsGroupBox->setStyle(clStyle);
retranslateUi(QDemoClass);
QMetaObject::connectSlotsByName(QDemoClass);
}
範例效果如下:
對於Qt 4.4的開發者而言,你可以參考jens的文章來讓你的程式也有GtkStyle的效果
http://labs.trolltech.com/page/Projects/Styles/GtkStyle
參考資料:
http://doc.trolltech.com/4.5/qt4-5-intro.html#graphics-enhancements
http://code.google.com/p/qgtkstyle/
http://labs.trolltech.com/page/Projects/Styles/GtkStyle
http://pepper.troll.no/s60prereleases/doc/qcleanlooksstyle.html
http://pepper.troll.no/s60prereleases/doc/qgtkstyle.html
I don't speak your language but I can still help you out here. This is an intentional change and not a bug in Qt 4.5.0 when running in GNOME because the GNOME 2.0 HIG dictates that group boxes should be borderless and should be similar to how group boxes look in control panels etc.
ReplyDeleteTo resolve this, you can either set a different style on the groupbox itself (cleanlooks for instance) or you can choose a specific border style other than styledpanel for the groupbox frame itself.
Thank you for providing the useful information to us. I will modify the post to make the information correct.
ReplyDelete