19阅读网  |  最近更新  |  TAG  | 
19阅读网
当前位置:首页 > qt界面设计

万博怎么样出黑-真正官方体育网投站

来源:互联网 时间:2017-07-21 阅读: 手机版

篇一:qt界面设计

1. 子窗体或控件,重写paintEvent事件,画边框、背景、文字、图片效果比较好。用paintEvent 事件画边框,用QPalette设置背景。https://blog.csdn.net/imxiangzi/article/details/50154951/

// 画边框https://blog.csdn.net/imxiangzi/article/details/50154951/

  QPainter painter(this);https://blog.csdn.net/imxiangzi/article/details/50154951/

  painter.setRenderHint(QPainter::Antialiasing, true);https://blog.csdn.net/imxiangzi/article/details/50154951/

  painter.setPen(QPen(QColor(225,70,56), 2));https://blog.csdn.net/imxiangzi/article/details/50154951/

//  painter.setBrush(QColor(16,62,81));  // 也可设置背景,有时效果不好https://blog.csdn.net/imxiangzi/article/details/50154951/

  painter.drawRoundedRect(rect(), 5.0, 5.0);https://blog.csdn.net/imxiangzi/article/details/50154951/

// 设置背景https://blog.csdn.net/imxiangzi/article/details/50154951/

  QPalette pal = palette();https://blog.csdn.net/imxiangzi/article/details/50154951/

  pal.setBrush(QPalette::Window, QColor(16,62,81));https://blog.csdn.net/imxiangzi/article/details/50154951/

  setPalette(pal);https://blog.csdn.net/imxiangzi/article/details/50154951/

  setAutoFillBackground(true); 继承QDialog,想让对话框以模态运行,使用exec(),继承时使用setWindowFlags()后则达不到模态的效果。不知道原因。 QStringList 输出https://blog.csdn.net/imxiangzi/article/details/50154951/

QStringList m_strLang English https://blog.csdn.net/imxiangzi/article/details/50154951/

  Chinese https://blog.csdn.net/imxiangzi/article/details/50154951/

qDebug( set language: %s , m_strLang.at(0).toLocal8Bit().constData()); QStringList 使用注意https://blog.csdn.net/imxiangzi/article/details/50154951/

  QStringList strDateformatList;https://blog.csdn.net/imxiangzi/article/details/50154951/

  strDateformatListhttps://blog.csdn.net/imxiangzi/article/details/50154951/

  m_strMonth - m_strDay - m_strYearhttps://blog.csdn.net/imxiangzi/article/details/50154951/

  m_strDay - m_strMonth - m_strYearhttps://blog.csdn.net/imxiangzi/article/details/50154951/

  m_strYear - m_strMonth - m_strDayhttps://blog.csdn.net/imxiangzi/article/details/50154951/

  ;https://blog.csdn.net/imxiangzi/article/details/50154951/

如果strDateformatList 在生命周期内多次调用,则会多次插入字符串,使得字符串重复,这不是我们想要的。那就定义为局部变量,每次会重新赋 ,达到更新的目的。需要动态重新的页面可以在showEvent函数中重新。 用paintEvent或用调色板为QWidget填充背景时,需要加上setAutoFillBackground(true);语句,否则没效果。 想使弹出的窗口为圆角,用paintEvent画圆角矩形,但四个直角仍然存在,不美观。可以把背景设为透明,用paintEvent画出想要的背景,因为四个角没有画上背景,是透明的,所以看不见。https://blog.csdn.net/imxiangzi/article/details/50154951/

  // 设置背景为透明 (构造函数中)https://blog.csdn.net/imxiangzi/article/details/50154951/

  QPalette pal = palette();https://blog.csdn.net/imxiangzi/article/details/50154951/

  pal.setBrush(QPalette::Window, QColor(255, 255, 255, 0));https://blog.csdn.net/imxiangzi/article/details/50154951/

  setPalette(pal);https://blog.csdn.net/imxiangzi/article/details/50154951/

  setAutoFillBackground(true);https://blog.csdn.net/imxiangzi/article/details/50154951/

  // 画背景和边框 (paintEvent函数中)https://blog.csdn.net/imxiangzi/article/details/50154951/

  QPainter painter(this);https://blog.csdn.net/imxiangzi/article/details/50154951/

  painter.setRenderHint(QPainter::Antialiasing, true);https://blog.csdn.net/imxiangzi/article/details/50154951/

  painter.setPen(QPen(QColor(225,70,56), 2));https://blog.csdn.net/imxiangzi/article/details/50154951/

  painter.setBrush(QColor(16,62,81));https://blog.csdn.net/imxiangzi/article/details/50154951/

  painter.drawRoundedRect(rect(), 5.0, 5.0); Qt::Key_Enter、Qt::Key_Returehttps://blog.csdn.net/imxiangzi/article/details/50154951/

Qt::Key_Enter对应小键盘的Enter键https://blog.csdn.net/imxiangzi/article/details/50154951/

Qt::Key_Return对应大键盘的Enter键 事件过滤。窗口部件的事件到达目的地之前提前获取并处理相关事件,实现个性化的处理。https://blog.csdn.net/imxiangzi/article/details/50154951/

我在QLabel对象中放入两个QPushButton对象和两个QLabel对象,QPushButton实现 的调节,其中一个QLabel对象用于显示 ,一个QLabel对象用于显示标题。类 SpinBox。在多个SpinBox上点击实现焦点切换,当鼠标点到QPushButton上时,QPushButton处理了mousePressEvent事件,所以无法实现焦点切换。为两个QPushButton对象安装事件过滤器,然后在其父部件中处理eventFilter函数https://blog.csdn.net/imxiangzi/article/details/50154951/

m_btnLeft- installEventFilter(this);https://blog.csdn.net/imxiangzi/article/details/50154951/

m_btnRight- installEventFilter(this);https://blog.csdn.net/imxiangzi/article/details/50154951/

//安装事件过滤器后,传给m_btnLeft、m_btnRight的事件会首先发送给eventFilter函数https://blog.csdn.net/imxiangzi/article/details/50154951/

bool ESpinBoxItem::eventFilter(QObject*obj,QEvent*ev)https://blog.csdn.net/imxiangzi/article/details/50154951/

{https://blog.csdn.net/imxiangzi/article/details/50154951/

if(obj == m_btnLeft || obj == m_btnRight)https://blog.csdn.net/imxiangzi/article/details/50154951/

{https://blog.csdn.net/imxiangzi/article/details/50154951/

if(ev- type() == QEvent::MouseButtonPress)https://blog.csdn.net/imxiangzi/article/details/50154951/

{https://blog.csdn.net/imxiangzi/article/details/50154951/

emit sign_spinBoxPressed(m_nItem);https://blog.csdn.net/imxiangzi/article/details/50154951/

return true; // 不传给目标对象处理https://blog.csdn.net/imxiangzi/article/details/50154951/

}https://blog.csdn.net/imxiangzi/article/details/50154951/

}https://blog.csdn.net/imxiangzi/article/details/50154951/

return false; // 不处理的事件则传给目标对象处理https://blog.csdn.net/imxiangzi/article/details/50154951/

}https://blog.csdn.net/imxiangzi/article/details/50154951/

10. 拍照动画https://blog.csdn.net/imxiangzi/article/details/50154951/

使用QTimeLine和QGraphicsPixmapItem对象,当时间线帧改变时,设置QGraphicsPixmapItem的位置,实现动画效果。https://blog.csdn.net/imxiangzi/article/details/50154951/

// 在QGraphicsView构造函数中https://blog.csdn.net/imxiangzi/article/details/50154951/

// take photo animationhttps://blog.csdn.net/imxiangzi/article/details/50154951/

  m_timerAnimation = new QTimeLine(900);https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_timerAnimation- setCurveShape(QTimeLine::LinearCurve);https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_timerAnimation- setFrameRange(0, 240);https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_pixmapUpAnimation = QPixmap( :/images/animation.png https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_pixmapDownAnimation = QPixmap( :/images/animation.png https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_upPixmapItem = new QGraphicsPixmapItem;https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_downPixmapItem = new QGraphicsPixmapItem;https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_upPixmapItem- setZValue(4);https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_downPixmapItem- setZValue(4);https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_upPixmapItem- setPos(0, 0);  // 左上角为原点https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_downPixmapItem- setPos(0, 240);https://blog.csdn.net/imxiangzi/article/details/50154951/

  scene()- addItem(m_upPixmapItem);https://blog.csdn.net/imxiangzi/article/details/50154951/

  scene()- addItem(m_downPixmapItem);https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_upPixmapItem- hide();https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_downPixmapItem- hide();https://blog.csdn.net/imxiangzi/article/details/50154951/

  connect(m_timerAnimation, SIGNAL(frameChanged(int)), this, SLOT(slot_playAnimation(int)));https://blog.csdn.net/imxiangzi/article/details/50154951/

// 槽函数https://blog.csdn.net/imxiangzi/article/details/50154951/

void EGraphicsView::slot_playAnimation(int nFrame)https://blog.csdn.net/imxiangzi/article/details/50154951/

{https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_upPixmapItem- show();https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_downPixmapItem- show();https://blog.csdn.net/imxiangzi/article/details/50154951/

  qDebug( nFrame: %d , nFrame);https://blog.csdn.net/imxiangzi/article/details/50154951/

  if(nFrame 120)https://blog.csdn.net/imxiangzi/article/details/50154951/

  {https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_upPixmapItem- setPixmap(m_pixmapUpAnimation.scaled(320, nFrame));https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_downPixmapItem- setPixmap(m_pixmapDownAnimation.scaled(320, nFrame));https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_downPixmapItem- setPos(0, 240 - nFrame);https://blog.csdn.net/imxiangzi/article/details/50154951/

  }https://blog.csdn.net/imxiangzi/article/details/50154951/

  elsehttps://blog.csdn.net/imxiangzi/article/details/50154951/

  {https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_upPixmapItem- setPixmap(m_pixmapUpAnimation.scaled(320, 240 - nFrame));https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_downPixmapItem- setPixmap(m_pixmapDownAnimation.scaled(320, 240 - nFrame));https://blog.csdn.net/imxiangzi/article/details/50154951/

  m_downPixmapItem- setPos(0, nFrame);https://blog.csdn.net/imxiangzi/article/details/50154951/

  }https://blog.csdn.net/imxiangzi/article/details/50154951/

}https://blog.csdn.net/imxiangzi/article/details/50154951/

11.在移动设备上使用渐变或使用渐变的图片时,会出现条纹状,达不到效果。在初始化QApplication对像前调用下面的语句则可以达到效果:https://blog.csdn.net/imxiangzi/article/details/50154951/

QApplication::setColorSpec(QApplication::ManyColor); //the right choice for applications that use thousands of colorshttps://blog.csdn.net/imxiangzi/article/details/50154951/

QApplication app(argc, argv,  QApplication::GuiServer );https://blog.csdn.net/imxiangzi/article/details/50154951/

12.用setStyleSheet设置背景图片https://blog.csdn.net/imxiangzi/article/details/50154951/

m_labelButton- setStyleSheet( background-image: url(:images/shutdown/slider.png); background-repeat: no-repeat; //注意,不加background-repeat: no-repeat可能会出现透视,很丑。QLabel对象可用setPixmap设置象素图。https://blog.csdn.net/imxiangzi/article/details/50154951/

13.使对话框圆角https://blog.csdn.net/imxiangzi/article/details/50154951/

  //构造函数中https://blog.csdn.net/imxiangzi/article/details/50154951/

  setAutoFillBackground(true);https://blog.csdn.net/imxiangzi/article/details/50154951/

  QPalette pal = palette();https://blog.csdn.net/imxiangzi/article/details/50154951/

  pal.setColor(QPalette::Window, QColor(0, 0, 0, 0));https://blog.csdn.net/imxiangzi/article/details/50154951/

  setPalette(pal);https://blog.csdn.net/imxiangzi/article/details/50154951/

  //paintEvent函数中https://blog.csdn.net/imxiangzi/article/details/50154951/

  QPainter painter(this);https://blog.csdn.net/imxiangzi/article/details/50154951/

  painter.setRenderHint(QPainter::Antialiasing,true);https://blog.csdn.net/imxiangzi/article/details/50154951/

  painter.setPen(QPen(Qt::red,2));https://blog.csdn.net/imxiangzi/article/details/50154951/

  painter.setBrush(QColor(16,62,81));https://blog.csdn.net/imxiangzi/article/details/50154951/

  painter.drawRoundedRect(rect(),5.0,5.0);https://blog.csdn.net/imxiangzi/article/details/50154951/

// 圆角处有杂色,原因不祥https://blog.csdn.net/imxiangzi/article/details/50154951/

14. 对某些默认事件的处理修改https://blog.csdn.net/imxiangzi/article/details/50154951/

正常情况下,按下Tab键,被QWidget看成是去移动键盘焦点,但少数窗口部件需要自行解释。https://blog.csdn.net/imxiangzi/article/details/50154951/

bool MyClass::event(QEvent *e)https://blog.csdn.net/imxiangzi/article/details/50154951/

{https://blog.csdn.net/imxiangzi/article/details/50154951/

  if(e- type() == QEvent::KeyPress)https://blog.csdn.net/imxiangzi/article/details/50154951/

  {https://blog.csdn.net/imxiangzi/article/details/50154951/

  QKeyEvent *ke = (QKeyEvent *)e;https://blog.csdn.net/imxiangzi/article/details/50154951/

  if(ke- key() == Qt::Key_Tab)https://blog.csdn.net/imxiangzi/article/details/50154951/

  {https://blog.csdn.net/imxiangzi/article/details/50154951/

  //这里是特定的Tab处理https://blog.csdn.net/imxiangzi/article/details/50154951/

  k- accept();https://blog.csdn.net/imxiangzi/article/details/50154951/

  return TRUE;https://blog.csdn.net/imxiangzi/article/details/50154951/

  }https://blog.csdn.net/imxiangzi/article/details/50154951/

  }https://blog.csdn.net/imxiangzi/article/details/50154951/

  else if(e- type()  = QEvent::User)https://blog.csdn.net/imxiangzi/article/details/50154951/

  {https://blog.csdn.net/imxiangzi/article/details/50154951/

  // 这里是自定义事件处理https://blog.csdn.net/imxiangzi/article/details/50154951/

  return TRUE;https://blog.csdn.net/imxiangzi/article/details/50154951/

  }https://blog.csdn.net/imxiangzi/article/details/50154951/

  QWidget::event(e);https://blog.csdn.net/imxiangzi/article/details/50154951/

}https://blog.csdn.net/imxiangzi/article/details/50154951/

  15.QLabel继承QFrame,有QFrame的特性。如setFrameStyle(int)可设置QLabel的FrameStyle(框架类型)https://blog.csdn.net/imxiangzi/article/details/50154951/

FrameStyle有两种:https://blog.csdn.net/imxiangzi/article/details/50154951/

a.第一种是frameshape:https://blog.csdn.net/imxiangzi/article/details/50154951/

有以下几种类型:https://blog.csdn.net/imxiangzi/article/details/50154951/

Constanthttps://blog.csdn.net/imxiangzi/article/details/50154951/

Valuehttps://blog.csdn.net/imxiangzi/article/details/50154951/

Descriptionhttps://blog.csdn.net/imxiangzi/article/details/50154951/

QFrame::NoFramehttps://blog.csdn.net/imxiangzi/article/details/50154951/

0https://blog.csdn.net/imxiangzi/article/details/50154951/

 draws nothinghttps://blog.csdn.net/imxiangzi/article/details/50154951/

QFrame::Boxhttps://blog.csdn.net/imxiangzi/article/details/50154951/

0x0001https://blog.csdn.net/imxiangzi/article/details/50154951/

 draws a box around its contentshttps://blog.csdn.net/imxiangzi/article/details/50154951/

QFrame::Panelhttps://blog.csdn.net/imxiangzi/article/details/50154951/

0x0002https://blog.csdn.net/imxiangzi/article/details/50154951/

 draws a panel to make the contents appear raised or sunkenhttps://blog.csdn.net/imxiangzi/article/details/50154951/

QFrame::StyledPanelhttps://blog.csdn.net/imxiangzi/article/details/50154951/

0x0006https://blog.csdn.net/imxiangzi/article/details/50154951/

draws a rectangular panel with a look that depends on the current GUI style. It can be raised or sunken.https://blog.csdn.net/imxiangzi/article/details/50154951/

QFrame::HLinehttps://blog.csdn.net/imxiangzi/article/details/50154951/

0x0004https://blog.csdn.net/imxiangzi/article/details/50154951/

 draws a horizontal line that frames nothing (useful as separator)https://blog.csdn.net/imxiangzi/article/details/50154951/

QFrame::VLinehttps://blog.csdn.net/imxiangzi/article/details/50154951/

0x0005https://blog.csdn.net/imxiangzi/article/details/50154951/

 draws a vertical line that frames nothing (useful as separator)https://blog.csdn.net/imxiangzi/article/details/50154951/

QFrame::WinPanelhttps://blog.csdn.net/imxiangzi/article/details/50154951/

0x0003https://blog.csdn.net/imxiangzi/article/details/50154951/

draws a rectangular panel that can be raised or sunken like those in Windows 95. Specifying this shape sets the line width to 2 pixels. WinPanel is provided for compatibility. For GUI style independence we recommend using StyledPanel instead.https://blog.csdn.net/imxiangzi/article/details/50154951/

b.第二种是frameshadowhttps://blog.csdn.net/imxiangzi/article/details/50154951/

有以下几种类型:https://blog.csdn.net/imxiangzi/article/details/50154951/

Constanthttps://blog.csdn.net/imxiangzi/article/details/50154951/

Valuehttps://blog.csdn.net/imxiangzi/article/details/50154951/

Descriptionhttps://blog.csdn.net/imxiangzi/article/details/50154951/

QFrame::Plainhttps://blog.csdn.net/imxiangzi/article/details/50154951/

0x0010https://blog.csdn.net/imxiangzi/article/details/50154951/

the frame and contents appear level with the surroundings; draws using the palettecolor (without any 3D effect)https://blog.csdn.net/imxiangzi/article/details/50154951/

QFrame::Raisedhttps://blog.csdn.net/imxiangzi/article/details/50154951/

0x0020https://blog.csdn.net/imxiangzi/article/details/50154951/

the frame and contents appear raised; draws a 3D raised line using the light and dark colors of the current color grouphttps://blog.csdn.net/imxiangzi/article/details/50154951/

QFrame::Sunkenhttps://blog.csdn.net/imxiangzi/article/details/50154951/

0x0030https://blog.csdn.net/imxiangzi/article/details/50154951/

the frame and contents appear sunken; draws a 3D sunken line using the light and dark colors of the current color grouphttps://blog.csdn.net/imxiangzi/article/details/50154951/

组合 的效果图:https://blog.csdn.net/imxiangzi/article/details/50154951/

  lineEdit =new QLineEdit;

 label- setBuddy(lineEdit);

  caseCheckBox= new QCheckBox(tr("Match case"));

 backwardCheckBox = new QCheckBox(tr("Search backward"));

  finon =new QPushButton(tr(" Find"));

 finon- setDefault(true);

 finon- setEnabled(false);

  closeButton= new QPushButton(tr("Close"));

 connect(lineEdit, SIGNAL(textChanged(const QString )),

 this, SLOT(enableFinon(const QString )));

 connect(finon, SIGNAL(clicked()),

 this, SLOT(findClicked()));

 connect(closeButton, SIGNAL(clicked()),

 this, SLOT(close()));

  //使用布局管理器布局控件

  QHBoxLayout*topLeftLayout = new QHBoxLayout;

 topLeftLayout- addWidget(label);

 topLeftLayout- addWidget(lineEdit);

  QVBoxLayout*leftLayout = new QVBoxLayout;

 leftLayout- addLayout(topLeftLayout);

 leftLayout- addWidget(caseCheckBox);

 leftLayout- addWidget(backwardCheckBox);

  QVBoxLayout*rightLayout = new QVBoxLayout;

 rightLayout- addWidget(finon);

 rightLayout- addWidget(closeButton);

 rightLayout- addStretch();

  QHBoxLayout*mainLayout = new QHBoxLayout;

 mainLayout- addLayout(leftLayout);

 mainLayout- addLayout(rightLayout);

  //设置窗口的布局管理器

 setLayout(mainLayout); 

 setWindowTitle(tr("Find"));

 setFixedHeight(sizeHint().height());

}

使用Qt Designer设计界面 采用Qt Designer,使得快速创建对话框成为可能。在QtDesigner环境中,所有的操作都采用可视化的操作,可拖放控件、关联信号与槽、设置特定控件的属性。使用QtDesigner设计界面的方法如下图所示:

 

猜你喜欢

最新文章

热门文章