• 20495阅读
  • 6回复

【提问】QLabel图标的问题 [复制链接]

上一主题 下一主题
离线shengma
 

只看楼主 倒序阅读 楼主  发表于: 2005-09-15
#include ".\ebl.h"
#include <QtGui/QMouseEvent>
#include <QtGui/QApplication>
#include <QtGui/QPixmap>
#include <QtGui/QMessageBox>



Ebl::Ebl(QWidget *parent)
{
    bEbl = FALSE;
    show();
}

Ebl::~Ebl()
{
}

void Ebl::mousePressEvent(QMouseEvent *e)
{
    if(e->button() == Qt::LeftButton){
//         QMessageBox::information(this, "mouse key", "this is mouse press");
        bEbl = !bEbl;
        if(bEbl){
        setPixmap(QPixmap(QString::fromUtf8("image\\ebldown.PNG")));

        }
        else{
        setPixmap(QPixmap(QString::fromUtf8("image\\ebldup.PNG")));

        }
    }
}


#pragma once
#include <QtGui/QLabel>

class Ebl :
    public QLabel
{
    Q_OBJECT
public:
    Ebl(QWidget *parent = 0);
  void mousePressEvent(QMouseEvent *e);

    bool bEbl;
    ~Ebl();
public slots:

signals:
 
};


#ifndef UI_ECDIS2006_H
#define UI_ECDIS2006_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QCheckBox>
#include <QtGui/QFrame>
#include <QtGui/QGroupBox>
#include <QtGui/QLCDNumber>
#include <QtGui/QLabel>
#include <QtGui/QPushButton>
#include <QtGui/QRadioButton>
#include <QtGui/QWidget>
#include "ebl.h"
#include "fr.h"
#include "go.h"
#include "ring.h"
#include "vrm.h"

class Ui_ECDIS2006Class
{
public:
  QLabel *label;
  QPushButton *Exit;
  QLabel *ToWP;
  QLabel *CursorlatLon;
  QLabel *Log;
  QLabel *Gyro;
  QPushButton *EBLSet;
  QLabel *EBLData;
  QPushButton *GoSet;
  QLabel *Ship;
  QLabel *Course;
  QLabel *Speed;
  QLabel *Cursor;
  QLabel *WP;
  QLabel *ToCursor;
  QCheckBox *Names;
  QLabel *ToCourse;
  Go *pGo;
  Fr *pFrame;
  Vrm *pVrm;
  Ebl *pEbl;
  QLabel *ShipLatLon;
  QLabel *Style;
  QLabel *Range;
  QPushButton *Down;
  QLabel *Logo;
  QGroupBox *Focus;
  QRadioButton *FocusSetting;
  QRadioButton *FocusMonitoring;
  QRadioButton *FocusPlanning;
  QRadioButton *FocusChart;
  QPushButton *Up;
  QFrame *ChartArea;
  QPushButton *Notes;
  QPushButton *Display;
  Ring *pRing;
  QLabel *GoData;
  QLabel *VRMData;
  QPushButton *VRMSet;
  QLCDNumber *Time;

  void setupUi(QWidget *ECDIS2006Class)
  {
  ECDIS2006Class->setObjectName(QString::fromUtf8("ECDIS2006Class"));
  ECDIS2006Class->resize(QSize(1280, 1026).expandedTo(ECDIS2006Class->minimumSizeHint()));
  label = new QLabel(ECDIS2006Class);
  label->setObjectName(QString::fromUtf8("label"));
  label->setGeometry(QRect(1150, 5, 35, 20));
  Exit = new QPushButton(ECDIS2006Class);
  Exit->setObjectName(QString::fromUtf8("Exit"));
  Exit->setGeometry(QRect(1220, 996, 50, 26));
  Exit->setCursor(QCursor(static_cast<Qt::CursorShape>(13)));
  ToWP = new QLabel(ECDIS2006Class);
  ToWP->setObjectName(QString::fromUtf8("ToWP"));
  ToWP->setGeometry(QRect(730, 2, 120, 26));
  ToWP->setCursor(QCursor(static_cast<Qt::CursorShape>(4)));
  ToWP->setFrameShape(QFrame::WinPanel);
  ToWP->setFrameShadow(QFrame::Sunken);
  ToWP->setLineWidth(2);
  CursorlatLon = new QLabel(ECDIS2006Class);
  CursorlatLon->setObjectName(QString::fromUtf8("CursorlatLon"));
  CursorlatLon->setGeometry(QRect(520, 2, 160, 26));
  CursorlatLon->setCursor(QCursor(static_cast<Qt::CursorShape>(4)));
  CursorlatLon->setFrameShape(QFrame::WinPanel);
  CursorlatLon->setFrameShadow(QFrame::Sunken);
  CursorlatLon->setLineWidth(2);
  Log = new QLabel(ECDIS2006Class);
  Log->setObjectName(QString::fromUtf8("Log"));
  Log->setGeometry(QRect(390, 2, 80, 26));
  Log->setCursor(QCursor(static_cast<Qt::CursorShape>(4)));
  Log->setFrameShape(QFrame::WinPanel);
  Log->setFrameShadow(QFrame::Sunken);
  Log->setLineWidth(2);
  Gyro = new QLabel(ECDIS2006Class);
  Gyro->setObjectName(QString::fromUtf8("Gyro"));
  Gyro->setGeometry(QRect(260, 2, 80, 26));
  Gyro->setCursor(QCursor(static_cast<Qt::CursorShape>(4)));
  Gyro->setFrameShape(QFrame::WinPanel);
  Gyro->setFrameShadow(QFrame::Sunken);
  Gyro->setLineWidth(2);
  EBLSet = new QPushButton(ECDIS2006Class);
  EBLSet->setObjectName(QString::fromUtf8("EBLSet"));
  EBLSet->setGeometry(QRect(43, 996, 26, 26));
  EBLSet->setCursor(QCursor(static_cast<Qt::CursorShape>(13)));
  EBLData = new QLabel(ECDIS2006Class);
  EBLData->setObjectName(QString::fromUtf8("EBLData"));
  EBLData->setGeometry(QRect(75, 996, 80, 26));
  EBLData->setCursor(QCursor(static_cast<Qt::CursorShape>(4)));
  EBLData->setFrameShape(QFrame::WinPanel);
  EBLData->setFrameShadow(QFrame::Sunken);
  GoSet = new QPushButton(ECDIS2006Class);
  GoSet->setObjectName(QString::fromUtf8("GoSet"));
  GoSet->setGeometry(QRect(369, 996, 26, 26));
  GoSet->setCursor(QCursor(static_cast<Qt::CursorShape>(13)));
  Ship = new QLabel(ECDIS2006Class);
  Ship->setObjectName(QString::fromUtf8("Ship"));
  Ship->setGeometry(QRect(10, 5, 30, 20));
  Ship->setPixmap(QPixmap(QString::fromUtf8("image\\ship.PNG")));
  Course = new QLabel(ECDIS2006Class);
  Course->setObjectName(QString::fromUtf8("Course"));
  Course->setGeometry(QRect(220, 2, 30, 26));
  Course->setPixmap(QPixmap(QString::fromUtf8("image\\gyro.PNG")));
  Speed = new QLabel(ECDIS2006Class);
  Speed->setObjectName(QString::fromUtf8("Speed"));
  Speed->setGeometry(QRect(350, 2, 30, 26));
  Speed->setPixmap(QPixmap(QString::fromUtf8("image\\log.PNG")));
  Cursor = new QLabel(ECDIS2006Class);
  Cursor->setObjectName(QString::fromUtf8("Cursor"));
  Cursor->setGeometry(QRect(480, 5, 30, 20));
  Cursor->setLineWidth(1);
  Cursor->setPixmap(QPixmap(QString::fromUtf8("image\\cursor5.PNG")));
  WP = new QLabel(ECDIS2006Class);
  WP->setObjectName(QString::fromUtf8("WP"));
  WP->setGeometry(QRect(690, 5, 30, 20));
  WP->setPixmap(QPixmap(QString::fromUtf8("image\\cursor4.PNG")));
  ToCursor = new QLabel(ECDIS2006Class);
  ToCursor->setObjectName(QString::fromUtf8("ToCursor"));
  ToCursor->setGeometry(QRect(860, 5, 30, 20));
  ToCursor->setPixmap(QPixmap(QString::fromUtf8("image\\cursor3.PNG")));
  Names = new QCheckBox(ECDIS2006Class);
  Names->setObjectName(QString::fromUtf8("Names"));
  Names->setGeometry(QRect(760, 996, 60, 26));
  Names->setCursor(QCursor(static_cast<Qt::CursorShape>(13)));
  ToCourse = new QLabel(ECDIS2006Class);
  ToCourse->setObjectName(QString::fromUtf8("ToCourse"));
  ToCourse->setGeometry(QRect(900, 2, 120, 26));
  ToCourse->setCursor(QCursor(static_cast<Qt::CursorShape>(4)));
  ToCourse->setFrameShape(QFrame::WinPanel);
  ToCourse->setFrameShadow(QFrame::Sunken);
  ToCourse->setLineWidth(2);
  pGo = new Go(ECDIS2006Class);
  pGo->setObjectName(QString::fromUtf8("pGo"));
  pGo->setGeometry(QRect(336, 996, 26, 26));
  pGo->setCursor(QCursor(static_cast<Qt::CursorShape>(13)));
  pGo->setPixmap(QPixmap(QString::fromUtf8("image\\goup.PNG")));
  pFrame = new Fr(ECDIS2006Class);
  pFrame->setObjectName(QString::fromUtf8("pFrame"));
  pFrame->setGeometry(QRect(535, 996, 26, 26));
  pFrame->setCursor(QCursor(static_cast<Qt::CursorShape>(13)));
  pFrame->setPixmap(QPixmap(QString::fromUtf8("image\\frameup.PNG")));
  pVrm = new Vrm(ECDIS2006Class);
  pVrm->setObjectName(QString::fromUtf8("pVrm"));
  pVrm->setGeometry(QRect(162, 996, 26, 26));
  pVrm->setPixmap(QPixmap(QString::fromUtf8("image\\vrmup.PNG")));
  pEbl = new Ebl(ECDIS2006Class);
  pEbl->setObjectName(QString::fromUtf8("pEbl"));
  pEbl->setGeometry(QRect(10, 996, 26, 26));
  pEbl->setCursor(QCursor(static_cast<Qt::CursorShape>(13)));
  pEbl->setPixmap(QPixmap(QString::fromUtf8("image\\ebldup.PNG")));
  ShipLatLon = new QLabel(ECDIS2006Class);
  ShipLatLon->setObjectName(QString::fromUtf8("ShipLatLon"));
  ShipLatLon->setGeometry(QRect(50, 2, 160, 26));
  ShipLatLon->setCursor(QCursor(static_cast<Qt::CursorShape>(4)));
  ShipLatLon->setFrameShape(QFrame::WinPanel);
  ShipLatLon->setFrameShadow(QFrame::Sunken);
  ShipLatLon->setLineWidth(2);
  Style = new QLabel(ECDIS2006Class);
  Style->setObjectName(QString::fromUtf8("Style"));
  Style->setGeometry(QRect(835, 996, 60, 26));
  Style->setCursor(QCursor(static_cast<Qt::CursorShape>(4)));
  Style->setFrameShape(QFrame::WinPanel);
  Style->setFrameShadow(QFrame::Sunken);
  Style->setLineWidth(12);
  Range = new QLabel(ECDIS2006Class);
  Range->setObjectName(QString::fromUtf8("Range"));
  Range->setGeometry(QRect(939, 996, 80, 26));
  Range->setFrameShape(QFrame::WinPanel);
  Range->setFrameShadow(QFrame::Sunken);
  Range->setLineWidth(12);
  Down = new QPushButton(ECDIS2006Class);
  Down->setObjectName(QString::fromUtf8("Down"));
  Down->setGeometry(QRect(1023, 996, 26, 26));
  Down->setCursor(QCursor(static_cast<Qt::CursorShape>(13)));
  Down->setIcon(QPixmap(QString::fromUtf8("image\\down.PNG")));
  Down->setIconSize(QSize(26, 26));
  Logo = new QLabel(ECDIS2006Class);
  Logo->setObjectName(QString::fromUtf8("Logo"));
  Logo->setGeometry(QRect(1121, 30, 150, 80));
  Logo->setPixmap(QPixmap(QString::fromUtf8("image\\logo.png")));
  Focus = new QGroupBox(ECDIS2006Class);
  Focus->setObjectName(QString::fromUtf8("Focus"));
  Focus->setGeometry(QRect(1121, 110, 151, 131));
  FocusSetting = new QRadioButton(Focus);
  FocusSetting->setObjectName(QString::fromUtf8("FocusSetting"));
  FocusSetting->setGeometry(QRect(10, 95, 121, 20));
  FocusSetting->setCursor(QCursor(static_cast<Qt::CursorShape>(13)));
  FocusMonitoring = new QRadioButton(Focus);
  FocusMonitoring->setObjectName(QString::fromUtf8("FocusMonitoring"));
  FocusMonitoring->setGeometry(QRect(10, 70, 121, 20));
  FocusMonitoring->setCursor(QCursor(static_cast<Qt::CursorShape>(13)));
  FocusPlanning = new QRadioButton(Focus);
  FocusPlanning->setObjectName(QString::fromUtf8("FocusPlanning"));
  FocusPlanning->setGeometry(QRect(10, 45, 121, 20));
  FocusPlanning->setCursor(QCursor(static_cast<Qt::CursorShape>(13)));
  FocusChart = new QRadioButton(Focus);
  FocusChart->setObjectName(QString::fromUtf8("FocusChart"));
  FocusChart->setGeometry(QRect(10, 20, 121, 20));
  FocusChart->setCursor(QCursor(static_cast<Qt::CursorShape>(13)));
  FocusChart->setContextMenuPolicy(Qt::ActionsContextMenu);
  Up = new QPushButton(ECDIS2006Class);
  Up->setObjectName(QString::fromUtf8("Up"));
  Up->setGeometry(QRect(909, 996, 26, 26));
  Up->setCursor(QCursor(static_cast<Qt::CursorShape>(13)));
  Up->setIcon(QPixmap(QString::fromUtf8("image\\up.PNG")));
  Up->setIconSize(QSize(26, 26));
  ChartArea = new QFrame(ECDIS2006Class);
  ChartArea->setObjectName(QString::fromUtf8("ChartArea"));
  ChartArea->setGeometry(QRect(1, 30, 1111, 964));
  ChartArea->setCursor(QCursor(static_cast<Qt::CursorShape>(2)));
  ChartArea->setFrameShape(QFrame::WinPanel);
  ChartArea->setFrameShadow(QFrame::Sunken);
  Notes = new QPushButton(ECDIS2006Class);
  Notes->setObjectName(QString::fromUtf8("Notes"));
  Notes->setGeometry(QRect(609, 996, 60, 26));
  Notes->setCursor(QCursor(static_cast<Qt::CursorShape>(13)));
  Display = new QPushButton(ECDIS2006Class);
  Display->setObjectName(QString::fromUtf8("Display"));
  Display->setGeometry(QRect(677, 996, 75, 26));
  Display->setCursor(QCursor(static_cast<Qt::CursorShape>(13)));
  pRing = new Ring(ECDIS2006Class);
  pRing->setObjectName(QString::fromUtf8("pRing"));
  pRing->setGeometry(QRect(572, 996, 26, 26));
  pRing->setCursor(QCursor(static_cast<Qt::CursorShape>(13)));
  pRing->setPixmap(QPixmap(QString::fromUtf8("image\\ringup.PNG")));
  GoData = new QLabel(ECDIS2006Class);
  GoData->setObjectName(QString::fromUtf8("GoData"));
  GoData->setGeometry(QRect(405, 996, 120, 26));
  GoData->setCursor(QCursor(static_cast<Qt::CursorShape>(4)));
  GoData->setFrameShape(QFrame::WinPanel);
  GoData->setFrameShadow(QFrame::Sunken);
  VRMData = new QLabel(ECDIS2006Class);
  VRMData->setObjectName(QString::fromUtf8("VRMData"));
  VRMData->setGeometry(QRect(230, 996, 100, 26));
  VRMData->setCursor(QCursor(static_cast<Qt::CursorShape>(4)));
  VRMData->setFrameShape(QFrame::WinPanel);
  VRMData->setFrameShadow(QFrame::Sunken);
  VRMSet = new QPushButton(ECDIS2006Class);
  VRMSet->setObjectName(QString::fromUtf8("VRMSet"));
  VRMSet->setGeometry(QRect(195, 996, 26, 26));
  VRMSet->setCursor(QCursor(static_cast<Qt::CursorShape>(13)));
  Time = new QLCDNumber(ECDIS2006Class);
  Time->setObjectName(QString::fromUtf8("Time"));
  Time->setGeometry(QRect(1190, 0, 80, 26));
  Time->setFrameShape(QFrame::WinPanel);
  Time->setFrameShadow(QFrame::Sunken);
  Time->setSegmentStyle(QLCDNumber::Filled);
  retranslateUi(ECDIS2006Class);
  QObject::connect(Exit, SIGNAL(clicked()), ECDIS2006Class, SLOT(close()));

  QMetaObject::connectSlotsByName(ECDIS2006Class);
  } // setupUi

  void retranslateUi(QWidget *ECDIS2006Class)
  {
  ECDIS2006Class->setWindowTitle(QApplication::translate("ECDIS2006Class", "ECDIS2006"));
  label->setText(QApplication::translate("ECDIS2006Class", ""));
  Exit->setText(QApplication::translate("ECDIS2006Class", "Exit"));
  ToWP->setText(QApplication::translate("ECDIS2006Class", "TextLabel"));
  CursorlatLon->setText(QApplication::translate("ECDIS2006Class", "TextLabel"));
  Log->setText(QApplication::translate("ECDIS2006Class", "TextLabel"));
  Gyro->setText(QApplication::translate("ECDIS2006Class", "TextLabel"));
  EBLSet->setText(QApplication::translate("ECDIS2006Class", "Set"));
  EBLData->setText(QApplication::translate("ECDIS2006Class", "TextLabel"));
  GoSet->setText(QApplication::translate("ECDIS2006Class", "Set"));
  Names->setText(QApplication::translate("ECDIS2006Class", "Names"));
  ToCourse->setText(QApplication::translate("ECDIS2006Class", "TextLabel"));
  pGo->setText(QApplication::translate("ECDIS2006Class", ""));
  pFrame->setText(QApplication::translate("ECDIS2006Class", ""));
  pVrm->setText(QApplication::translate("ECDIS2006Class", ""));
  pEbl->setText(QApplication::translate("ECDIS2006Class", ""));
  ShipLatLon->setText(QApplication::translate("ECDIS2006Class", "TextLabel"));
  Style->setText(QApplication::translate("ECDIS2006Class", "TextLabel"));
  Range->setText(QApplication::translate("ECDIS2006Class", "TextLabel"));
  Down->setText(QApplication::translate("ECDIS2006Class", ""));
  Logo->setText(QApplication::translate("ECDIS2006Class", ""));
  Focus->setTitle(QApplication::translate("ECDIS2006Class", "FOCUS"));
  FocusSetting->setText(QApplication::translate("ECDIS2006Class", "Setting"));
  FocusMonitoring->setText(QApplication::translate("ECDIS2006Class", "Monitoring"));
  FocusPlanning->setText(QApplication::translate("ECDIS2006Class", "Planning"));
  FocusChart->setText(QApplication::translate("ECDIS2006Class", "Chart"));
  Up->setText(QApplication::translate("ECDIS2006Class", ""));
  Notes->setText(QApplication::translate("ECDIS2006Class", "Notes"));
  Display->setText(QApplication::translate("ECDIS2006Class", "Display"));
  pRing->setText(QApplication::translate("ECDIS2006Class", ""));
  GoData->setText(QApplication::translate("ECDIS2006Class", "TextLabel"));
  VRMData->setText(QApplication::translate("ECDIS2006Class", "TextLabel"));
  VRMSet->setText(QApplication::translate("ECDIS2006Class", "Set"));
  Q_UNUSED(ECDIS2006Class);
  } // retranslateUi

};

namespace Ui {
  class ECDIS2006Class: public Ui_ECDIS2006Class {};
} // namespace Ui

#endif // UI_ECDIS2006_H

如图片所示,按钮出现在另一个窗口中了,本意是按钮在主窗口中。
[ 此贴被XChinux在2005-09-15 22:55重新编辑 ]
离线XChinux

只看该作者 1楼 发表于: 2005-09-15
是不是你的QLabel的Parent设置的不对?
就是构造的时候parent设置错了。
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线shengma

只看该作者 2楼 发表于: 2005-09-16
我也这么想,可还是找不出哪里出错了。
离线XChinux

只看该作者 3楼 发表于: 2005-09-16
Ebl::Ebl(QWidget *parent)
{
  bEbl = FALSE;
  show();
}
加上个:QLabel(parent)
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线shengma

只看该作者 4楼 发表于: 2005-09-16
版大,是这问题,构造函数为什么要这样写呢?
离线shengma

只看该作者 5楼 发表于: 2005-09-16
现在的效果如图。
离线XChinux

只看该作者 6楼 发表于: 2005-09-16
要把parent指针传进去的,要是parent不是你要指定的那个部件,它就不知道跑到哪里去了。
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
快速回复
限100 字节
 
上一个 下一个