16,202
社区成员
发帖
与我相关
我的任务
分享
LineEdit *letedit = new LineEdit("");
ui->twEditMarkers->setCellWidget(i,2,letedit);
#include <QLineEdit>
class LineEdit : public QLineEdit
{
Q_OBJECT
public:
LineEdit(QWidget *parent = 0);
~LineEdit();
protected:
//void focusInEvent(QFocusEvent *event);
void mousePressEvent(QMouseEvent *event);
};
接下来新类LineEdit,可以像QLineEdit一样使用了。
void LineEdit::mousePressEvent( QMouseEvent *event )
{
m_beenShown = false;
QColor initialColor(255, 0, 0);
QColor pickColor = QColorDialog::getColor(initialColor, this, tr("Pick Color"));
if (pickColor.isValid())
{
QString strColor = QString("(%1, %2, %3)").arg(pickColor.red()).arg(pickColor.green()).arg(pickColor.blue());
setText(strColor);
}
}
if (hasFocus())
{
}
void LineEdit::mousePressEvent( QMouseEvent * event )
{
if (!hasFocus())
{
// show the dialog like before
}
}
[/quote]
再次点击的时候
focusInEvent(
mousePressEvent
这个方法都不走是咋回事呢?
lette.setColor(QPalette::Text, color);
和
lineedit->setStyleSheet("color:rgb(0,255,255)");
[/quote]
全都搞定,多谢大哥的热心帮助,没大哥这个问题估计得搞个2,3天
lette.setColor(QPalette::Text, color);
和
lineedit->setStyleSheet("color:rgb(0,255,255)");
ts << color.name() << "\n";
这样读取就比较方便
QString binPath = QCoreApplication::applicationDirPath();
QString filePath = binPath + "/color.txt";
QFile file(filePath);
if (!file.open(QFile::ReadOnly | QIODevice::Text))
{
return;
}
QTextStream ts(&file);
QStringList slColor;
while (!ts.atEnd())
{
slColor << ts.readLine();
}
file.close();
QPalette palette;
for (int i = 0; i < m_table->rowCount() && i < slColor.size(); i++)
{
LineEdit* le = (LineEdit *)m_table->cellWidget(i, 2);
QColor color(slColor.at(i));
palette.setColor(QPalette::Base, color);
le->setPalette(palette);
}