我正在尝试在 Ubuntu 13.04 中创建一个亮度控制应用程序。这个想法是制作一个托盘图标和滑块,在按下图标时出现。问题是托盘菜单只包含一个空项目。这是代码块,它工作但不正确(它仅在按下空菜单项时显示滑块):
cntrl::cntrl(QWidget *parent):
QWidget(parent)
{
value = 2500;
slider = new QSlider (Qt::Horizontal,this);
slider->setValue(2500);
slider -> setRange(0,maxBrightness);
slider -> setSingleStep(50);
slider->setPageStep(50);
tray = new QSystemTrayIcon (this);
menu = new QMenu (this);
act = new QWidgetAction (this);
act->setDefaultWidget(slider);
menu->addAction(act);
tray->setContextMenu(menu);
tray->setIcon(QIcon(":/brightness2.png"));
tray->show();
connect (slider,SIGNAL(valueChanged(int)),this,SLOT(changeBrightness(int)));
connect(act,SIGNAL(triggered()),menu,SLOT(show())); //trying to make it work somehow
}
怎么了 ?