Results 1 to 4 of 4

Thread: Problem with custom widget

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Posts
    32
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Problem with custom widget

    Hi ,

    I am trying to customized QTableWidget Item in Qt-4.1 version(linux). It is compiling
    properly and creating Libraries. When instatiating the plugin widgets instead of my class object, it is creating object of base class(QTableWidget). I am not getting the error position. So asking for ur help. Attaching the code.

    //spreadsheet.h

    #ifndef SPREADSHEET
    #define SPREADSHEET
    #include <QApplication>
    #include <Qt3Support>
    #include <QTableWidget>
    #include <Q3PopupMenu>
    #include <QAction>
    #include <QColorDialog>

    class SpreadSheet : public QTableWidget {
    //Q_OBJECT
    public :
    SpreadSheet (QWidget* a_parent = 0);
    SpreadSheet (int a_row = 1, int a_column = 4,
    QWidget *a_parent = 0);
    void CreatePopupMenu();
    void ChooseColor ();
    void ExecPopupMenu(int, int);
    private:
    unsigned row;
    unsigned column;
    Q3PopupMenu *menu;
    QAction *colorBackAct;
    QAction *colorTextAct;
    QColor color;
    };

    #endif

    //spreadsheet.cpp
    #include "spreadsheet.h"

    SpreadSheet :: SpreadSheet (QWidget* a_parent)
    :QTableWidget(a_parent)
    {
    row = 0;
    column = 0;
    CreatePopupMenu();
    }

    SpreadSheet :: SpreadSheet (int a_row, int a_column, QWidget* a_parent)
    : QTableWidget(a_row, a_column, a_parent)
    {
    row = a_row;
    column = a_column;
    CreatePopupMenu();
    }

    void
    SpreadSheet :: CreatePopupMenu()
    {
    connect(this, SIGNAL(cellDoubleClicked(int, int)),
    this, SLOT(ExecPopupMenu(int, int)));

    menu = new Q3PopupMenu(this);
    menu->addAction("Cell Background color ... ", this, SLOT(ChooseColor()));
    menu->addAction("Cell Text Color ...", this, SLOT(ChooseColor()));
    }

    void
    SpreadSheet :: ChooseColor()
    {
    color = QColorDialog::getColor();
    }


    void
    SpreadSheet :: ExecPopupMenu(int a_row, int a_column)
    {
    menu->exec();
    // QWidget* widget = cellWidget(a_row, a_column);
    QTableWidgetItem *item = takeItem(a_row, a_column);
    item->setBackgroundColor (color);
    }

    //customwidgetplugin.h
    #ifndef CUSTOMWIDGETPLUGIN_H
    #define CUSTOMWIDGETPLUGIN_H

    #include <QDesignerCustomWidgetInterface>

    class SpreaSheetPlugin : public QObject, public QDesignerCustomWidgetInterface
    {
    Q_OBJECT
    Q_INTERFACES(QDesignerCustomWidgetInterface)

    public:
    SpreaSheetPlugin(QObject *parent = 0);

    bool isContainer() const;
    bool isInitialized() const;
    QIcon icon() const;
    QString codeTemplate() const;
    QString domXml() const;
    QString group() const;
    QString includeFile() const;
    QString name() const;
    QString toolTip() const;
    QString whatsThis() const;
    QWidget *createWidget(QWidget *parent);
    void initialize(QDesignerFormEditorInterface *core);

    private:
    bool initialized;
    };

    #endif

    //customwidgetplugin.cpp
    #include "spreadsheet.h"
    #include "customwidgetplugin.h"

    #include <QtPlugin>

    SpreaSheetPlugin::SpreaSheetPlugin(QObject *parent)
    : QObject(parent)
    {
    initialized = false;
    }

    void SpreaSheetPlugin::initialize(QDesignerFormEditorIn terface * /* core */)
    {
    if (initialized)
    return;

    initialized = true;
    }

    bool SpreaSheetPlugin::isInitialized() const
    {
    return initialized;
    }

    QWidget *SpreaSheetPlugin::createWidget(QWidget *parent)
    {
    return (new SpreadSheet(2,3, parent));
    }

    QString SpreaSheetPlugin::name() const
    {
    return "SpreadSheet";
    }

    QString SpreaSheetPlugin::group() const
    {
    return "Display Widgets [Examples]";
    }

    QIcon SpreaSheetPlugin::icon() const
    {
    return QIcon();
    }

    QString SpreaSheetPlugin::toolTip() const
    {
    return "";
    }

    QString SpreaSheetPlugin::whatsThis() const
    {
    return "";
    }

    bool SpreaSheetPlugin::isContainer() const
    {
    return false;
    }

    QString SpreaSheetPlugin::domXml() const
    {
    return "<widget class=\"SpreadSheet\" name=\"spreadSheet\">\n"
    " <property name=\"geometry\">\n"
    " <rect>\n"
    " <x>0</x>\n"
    " <y>0</y>\n"
    " <width>300</width>\n"
    " <height>300</height>\n"
    " </rect>\n"
    " </property>\n"
    " <property name=\"toolTip\" >\n"
    " <string> Spread Sheet</string>\n"
    " </property>\n"
    " <property name=\"whatsThis\" >\n"
    " <string> Spread sheet: Items are displayed "
    " in table format.</string>\n"
    " </property>\n"
    "</widget>\n";
    }

    QString SpreaSheetPlugin::includeFile() const
    {
    return "spreadsheet.h";
    }

    QString SpreaSheetPlugin::codeTemplate() const
    {
    return "";
    }

    Q_EXPORT_PLUGIN2(customwidgetplugin, SpreaSheetPlugin)
    Attached Files Attached Files

Similar Threads

  1. Widget background problem.
    By zgulser in forum Qt Tools
    Replies: 2
    Last Post: 6th January 2009, 06:34
  2. custom plug-in widget in another custom plug-in widget.
    By MrGarbage in forum Qt Programming
    Replies: 6
    Last Post: 27th August 2007, 15:38
  3. Simple custom widget won't size properly
    By MrGarbage in forum Qt Tools
    Replies: 2
    Last Post: 9th August 2007, 13:12
  4. Custom tab widget question
    By PrimeCP in forum Qt Programming
    Replies: 2
    Last Post: 7th August 2007, 11:17
  5. Replies: 4
    Last Post: 1st March 2006, 23:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.