QSpinBox non appare



  • Salve a tutti. Ho iniziato a usare da poco Qt e avrei un problema: Dopo aver creato la finestra principale e una QTable, ho creato una QGroupBox e vorrei che all'interno di quest'ultima coi fosse una QSpinBox. Questo è il mio tentativo, ma appare tutto tranne la QSpinBox:

    @
    //mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QTableWidget>
    #include <QGroupBox>
    #include <QSpinBox>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);

    ~MainWindow();
    

    public slots:
    void cellSelected(int nRow, int nCol);

    private:
    Ui::MainWindow *ui;

    QTableWidget* m_pTableWidget;
    QStringList m_TableHeader;
    
    QGroupBox* gb1;
    QSpinBox* numericupdown;
    

    };

    #endif // MAINWINDOW_H

    //mainwindow.cpp

    #include "mainwindow.h"

    #include <QApplication>
    #include <QDesktopWidget>
    #include <QtCore/QCoreApplication>
    #include <QHeaderView>
    #include <QMessageBox>

    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent),
    m_pTableWidget(NULL)
    {
    resize(950, 600);
    m_pTableWidget = new QTableWidget(this);
    m_pTableWidget->setRowCount(4);
    m_pTableWidget->setColumnCount(3);
    m_TableHeader<<"A"<<"B"<<"C";
    m_pTableWidget->setHorizontalHeaderLabels(m_TableHeader);
    m_pTableWidget->resizeColumnsToContents();
    m_pTableWidget->verticalHeader()->setVisible(false);
    m_pTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
    m_pTableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
    m_pTableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
    m_pTableWidget->setShowGrid(true);
    m_pTableWidget->setStyleSheet("QTableView {selection-background-color: grey;}");
    m_pTableWidget->horizontalHeader()->setDefaultSectionSize(115);
    m_pTableWidget->verticalHeader()->setDefaultSectionSize(20);
    m_pTableWidget->horizontalHeader()->setHighlightSections(false);
    //m_pTableWidget->setGeometry(QApplication::desktop()->screenGeometry());
    m_pTableWidget->move(30, 25);
    m_pTableWidget->resize(350, 151);

    //insert data
    m_pTableWidget->setItem(0, 0, new QTableWidgetItem("Hello"));
    
    connect( m_pTableWidget, SIGNAL( cellDoubleClicked (int, int) ),
             this, SLOT( cellSelected( int, int ) ) );
    
    gb1 = new QGroupBox(this);
    gb1->move(30, 180);
    gb1->resize(160, 75);
    numericupdown = new QSpinBox(this);
    numericupdown->move(106, 17);
    numericupdown->resize(50, -1);
    numericupdown->setRange(-20, 20);
    numericupdown->setSingleStep(1);
    numericupdown->setValue(0);
    

    }

    MainWindow::~MainWindow()
    {
    }

    void MainWindow::cellSelected(int nRow, int nCol)
    {
    QMessageBox::information(this, "",
    "Cell at row "+QString::number(nRow)+
    " column "+QString::number(nCol)+
    " was double clicked.");
    }
    @



  • Ti consiglio di usare l'ide per disegnare le interfacce grafiche altrimenti rischi di pedere un sacco dui tempo.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.