編制了一個程式,需要用到QTableWidget和QPainter,遇到以下問題:1. 若只有QTableWidget或者QPainter都能正常作業,但是如果把兩個都加上,則只顯示QTableWidget,不能顯示QPainter。 將mainwindow.cpp中的vlayout->addWidget(table);注釋掉,則正確顯示圖形,如下圖:
window.open('http://www.qtcn.org/bbs/attachment/Mon_1111/17_108454_705c52fb902b9a0.png?4');" style="max-width:700px;max-height:700px;" onload="if(is_ie6&&this.offsetWidth>700)this.width=700;" >將mainwindow.cpp中的vlayout->addWidget(table); 注釋打開,則只能顯示table,不能顯示painter,如下圖:
2. 請教如何做到既顯示QTableWidget又能正確顯示QPainter,謝謝! ----------------------------------------main.cpp---------------------------------------int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow *mainwindow=new MainWindow; mainwindow->show(); return a.exec();}----------------------------------------mainwindow.h---------------------------------------#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QtGui> class QPushButton;class QTableWidget;class QLabel;class QLineEdit;class RenderArea;class MainWindow : public QMainWindow{ Q_OBJECTpublic: MainWindow(); ~MainWindow();private: QLabel *nvlabel,*nlooplabel; QLineEdit *nvlineedit,*nlooplineedit; QTableWidget *table,*abc_table; QPushButton *fitButton,*closeButton,*okButton,*paint_Button; QHBoxLayout *tophlayout,*hlo; QVBoxLayout *vlayout; QWidget *window; RenderArea *renderArea;private: void initWidgets();private slots: void create_table(); };#endif // MAINWINDOW_H----------------------------------------mainwindow.cpp---------------------------------------#include "mainwindow.h"#include "render.h"#include <QtGui>MainWindow::MainWindow(){ initWidgets();} MainWindow::~MainWindow(){}void MainWindow::initWidgets(){ //表格 table=new QTableWidget; //按鈕 QString a1=tr("回歸ABC"); fitButton= new QPushButton(a1); QString a2=tr("關閉程式"); closeButton=new QPushButton(a2); QString a3=tr("確定引數"); okButton=new QPushButton(a3); //label QString a4=tr("拉速個數"); nvlabel=new QLabel(a4); QString a5=tr("回路個數"); nlooplabel=new QLabel(a5); //上方,水平layout tophlayout = new QHBoxLayout; tophlayout->addWidget(nvlabel); tophlayout->addWidget(nvlineedit); tophlayout->addWidget(nlooplabel); tophlayout->addWidget(nlooplineedit); tophlayout->addWidget(okButton); tophlayout->addStretch(); renderArea = new RenderArea; //整體layout vlayout = new QVBoxLayout; vlayout->addLayout(tophlayout); vlayout->addWidget(table); vlayout->addWidget(renderArea); window = new QWidget; window->setLayout(vlayout); setWindowTitle(tr("fit ABC")); setCentralWidget(window); showMaximized();} void MainWindow::create_table(){ nv=nvlineedit->text().toInt();}---------------------------------------------------------render.h---------------------------------------------------#ifndef RENDERAREA_H#define RENDERAREA_H#include <QWidget>class RenderArea : public QWidget{ Q_OBJECTpublic: RenderArea(QWidget *parent = 0);protected: void paintEvent(QPaintEvent *event);};#endif---------------------------------------------------------render.cpp---------------------------------------------------#include <QtGui>#include "render.h"RenderArea::RenderArea(QWidget *parent): QWidget(parent){ setBackgroundRole(QPalette::Base); setAutoFillBackground(true);} void RenderArea::paintEvent(QPaintEvent * /* event */){ static const QPoint points[4] = { QPoint(10, 80), QPoint(20, 10), QPoint(80, 30), QPoint(90, 70) };}
uj5u.com熱心網友回復:
mTableWidget->setStyleSheet("background-color:transparent");轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/11705.html
標籤:其他技術討論專區
下一篇:AHK代碼求助
