在派生类中调用父类的绘画事件?
在QDockWidget
派生类中我enable style sheet支持如下:在派生类中调用父类的绘画事件?
void CDockWidget::paintEvent(QPaintEvent *event)
{
QStyleOption opt;
opt.initFrom(this);
QPainter p(this);
this->style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
// call QDockWidget::paintEvent(event) here ???????
// I have called QDockWidget::paintEvent(event) here, but did not notice any difference
}
问:我必须调用父类paintEvent
或这是错的(如果是的话请详细说明)。在原始code example父函数是不是调用,但我想知道这是否正确?它会错过任何功能,不是吗?
注:上述代码允许如所描述的使用样式表与派生类: Qt stylesheet in derived class in C++ namespace (selector)
这就是QDockWidget内部一样。看起来您的布局管理不会发生在您当前的代码中。我希望你可以通过调整窗口大小或类似的东西来调整布局来看问题。
void QDockWidget::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event)
QDockWidgetLayout *layout
= qobject_cast<QDockWidgetLayout*>(this->layout());
bool customTitleBar = layout->widgetForRole(QDockWidgetLayout::TitleBar) != 0;
bool nativeDeco = layout->nativeWindowDeco();
if (!nativeDeco && !customTitleBar) {
QStylePainter p(this);
// ### Add PixelMetric to change spacers, so style may show border
// when not floating.
if (isFloating()) {
QStyleOptionFrame framOpt;
framOpt.init(this);
p.drawPrimitive(QStyle::PE_FrameDockWidget, framOpt);
}
// Title must be painted after the frame, since the areas overlap, and
// the title may wish to extend out to all sides (eg. XP style)
QStyleOptionDockWidgetV2 titleOpt;
initStyleOption(&titleOpt);
p.drawControl(QStyle::CE_DockWidgetTitle, titleOpt);
}
}
奇怪的是,我没有注意到我是否调用父函数或没有任何区别... – 2014-11-24 17:10:01
@HorstWalter嗯...你可能安全吗?我无法准确跟踪代码合法地做了什么...... – 2014-11-24 17:19:53
它允许使用具有派生类的样式表(如果您有兴趣,请参阅问题更新)。它是如何工作的详细我不知道,这是这样做的通用代码(在上面链接的Qt网站上找到)。没有你不能使用派生类的样式表选择器 – 2014-11-24 18:13:53
我不知道,但我认为你应该画一个'将QStyle :: PE_FrameDockWidget'代替'将QStyle :: PE_Widget'的。试试看并检查。 – Iuliu 2014-11-24 12:28:40