Qt, how to remove the frame of widget - qt

I realize two QPlainTextEdit and lay them in one QSplitter, but the margin of these two widgets is a bit large. I also notice the wigets of Qt creator is very compact. I don't know how to reduce the distance of my widgets.
I post my code below:
QVBoxLayout * spuvbox = new QVBoxLayout ;
SPUEdit = new CodeEditor;
QLabel *label1 = new QLabel("SPU Code");
spuvbox->addWidget(label1);
spuvbox->addWidget(SPUEdit);
QWidget * spuwidget = new QWidget;
spuwidget->setLayout(spuvbox);
QVBoxLayout * mpuvbox = new QVBoxLayout ;
MPUEdit = new CodeEditor;
QLabel *label2 = new QLabel("MPU Code");
mpuvbox->addWidget(label2);
mpuvbox->addWidget(MPUEdit);
QWidget * mpuwidget = new QWidget;
mpuwidget->setLayout(mpuvbox);
QSplitter * textsplitter = new QSplitter(Qt::Horizontal,0);
textsplitter->setHandleWidth(2);
textsplitter->addWidget(spuwidget);
textsplitter->addWidget(mpuwidget);
setCentralWidget(textsplitter);

Related

Qt qwt - error: 'QwtLog10ScaleEngine' does not name a type' [duplicate]

Version: qwt 6.0.1
I've tried to develop logarithmic scaling for Spectrum.
I've used simple line to enable scaling plotspectrum->setAxisScaleEngine(QwtPlot::yLeft, new QwtLog10ScaleEngine);
Problems: the data are not drawn, so the plot is empty and the compiler returns following error:"expected type-specifier before 'QwtLog10ScaleEngine'"
Any help woulb be appreciated
Here is my code:
class SpectrumPlot : public QWidget
{
Q_OBJECT
public:
PlotSpektrum();
private:
QHBoxLayout* m_SpectrumLayout;
QwtPlot* m_SpectrumPlot;
QwtPlotCurve* m_SpectrumCurve;
QwtPlotMarker* m_Marker;
};
SpectrumPlot::SpectrumPlot()
{
m_SpectrumLayout = new QHBoxLayout();
m_SpectrumPlot = new QwtPlot();
m_SpectrumCurve = new QwtPlotCurve();
QwPlotGrid* pGrid = new QwtPlotGrid();
QPen GridPen;
GridPen.setColor(Qt::green);
GridPen.setWidthF(0.7);
GridPen.setStyle(Qt::DashLine);
QPen SpectrumPen;
SpectrumPen.setColor(Qt::white);
pGrid->setRenderHint(QwtPlotItem::RenderAntialiased);
pGrid->setPen(GridPen);
pGrid->enableXMin(true);
pGrid->attach(m_SpectrumPlot);
m_SpectrumPlot->setTitle("Spectrum");
m_SpectrumPlot->setCanvasBackground(QBrush(Qt::black));
m_SpectrumPlot->setAutoDelete(true);
m_SpectrumPlot->setAxisTitle(QwtPlot::xBottom, "Frequency Hz");
m_SpectrumPlot->setAxisScale(QwtPlot::xBottom, 100, nNyquistFrequency);
m_SpectrumPlot->setAxisScale(QwtPlot::yLeft, 0, 150);
m_SpectrumPlot->setAxisScaleEngine(QwtPlot::xBottom, new QwtLog10ScaleEngine());
m_SpectrumLayout->addWidget(m_SpectrumPlot);
this->setLayout(m_SpectrumLayout);
}
I think you should be using:
new QwtLogScaleEngine(10)
The manual for QwtScaleEngine doesn't show any classes called QwtLog10ScaleEngine.

QHBoxLayout addwidget() order and two qglwidget share texture object

I created two QGLwidget objects:
slicerCanvas* slicerX_;
secCan* secWid_;
secWid_ = new secCan(this);
//slicerX_ load data and create texture object share with secWid_
slicerX_ = new slicerCanvas(this,secWid_);
and in the main window, I use QHBoxLayout:
hBox_ = new QHBoxLayout;
hBox_->addWidget(slicerX_);
hBox_->addWidget(secWid_);
centerWidget_->setLayout(hBox_);
It works right, but if I addWidget like this:
hBox_ = new QHBoxLayout;
hBox_->addWidget(secWid_);//first
hBox_->addWidget(slicerX_);//second
centerWidget_->setLayout(hBox_);
The secWid_ will not paint anything, only slicerX_ paints correctly. I am confused as to why.

Why do the next two code sequences behave differently?

I don't understand why the first code sequence creates a QWidget where the elements overlap, while the second one behaves correctly.
The only difference is that in the first one there is a QVBoxLayout pointer, while in the second one it's an object.
It's about passing by reference vs passing by pointer? I really don't get the subtle difference.
First one:
QVBoxLayout vbox;
vbox.setSpacing(2);
QPushButton* quitButton = new QPushButton("Qsdfsuit");
QFont fnt = quitButton->font();
fnt.setPointSize(18);
fnt.setBold(true);
fnt.setFamily("Arial");
quitButton->setFont(fnt);
connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
QLCDNumber* lcd = new QLCDNumber(2);
QSlider* slider = new QSlider(Qt::Horizontal);
slider->setRange(0, 99);
slider->setValue(0);
connect(slider, SIGNAL(valueChanged(int)), lcd, SLOT(display(int)));
vbox.addWidget(quitButton);
vbox.addWidget(lcd);
vbox.addWidget(slider);
this->setLayout(&vbox);
The second one:
QVBoxLayout* vbox = new QVBoxLayout();
vbox->setSpacing(2);
QPushButton* quitButton = new QPushButton("Qsdfsuit");
QFont fnt = quitButton->font();
fnt.setPointSize(18);
fnt.setBold(true);
fnt.setFamily("Arial");
quitButton->setFont(fnt);
connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
QLCDNumber* lcd = new QLCDNumber(2);
QSlider* slider = new QSlider(Qt::Horizontal);
slider->setRange(0, 99);
slider->setValue(0);
connect(slider, SIGNAL(valueChanged(int)), lcd, SLOT(display(int)));
vbox->addWidget(quitButton);
vbox->addWidget(lcd);
vbox->addWidget(slider);
this->setLayout(vbox);
In the first segment QVBoxLayout vbox; is created on the stack.
It is destroyed as soon as the method execution if finished.
In the second segment QVBoxLayout* box is created in a heap and it's not destroyed until the widget is alive.
Layouts in Qt do their job when a widget is shown or resized that's why they should exist until a widget exists.
More information:
The stack and the heap
Blocks and local variables

QGraphicsProxyWidget::setPos(qreal x, qreal y) doesn't place correctly in a QGraphicsScene when coordinates > 2^15

I have a QGraphicsScene of big dimension for displaying a database content.
Part of the database is made of pictures that I place in the QGraphicsScene thanks to the method setPos() of a QGraphicsPixmapItem and this works fine with thousands of pictures.
In front of these pictures, I place QCheckboxes that are finally accessible through QGraphicsProxyWidgets. But QGraphicsProxyWidget::setPos(qreal x, qreal y) results in casting provided coordinates in signed short in the QGraphicsScene.
However, doing a QGraphicsProxyWidget::pos() returns correctly the original coordinates, even above 2^16.
Here is the code:
QCheckBox* checkbox = new QCheckBox("", this);
QWidget* dummyWidget = new QWidget; //used for having a transparent background
dummyWidget->setStyleSheet("background-color:transparent;"
"outline-color:transparent;"
"font-size: 8pt;");
QHBoxLayout* dummyLayout = new QHBoxLayout(dummyWidget);
dummyLayout->addWidget(checkbox);
QGraphicsProxyWidget* proxyWidget = scene.addWidget(dummyWidget);
proxyWidget->setPos(0, 120*i);
When 120*i is between 32769 and 65536, QChekBoxes don't show. For above values, QCheckBoxes are shown like if y = value - 65536.
I have tried many things without success, like
- proxyWidget->moveBy
- dummyWidget->move
- dummyWidget->setFixedSize(0, 240*i); checkbox->move(0, 120*i);
Any solution?
PS: The toolchain/cross-toolchain I depend from embeds QT4.8.1. for the desktop side.
I have no way to change that so upgrading to QT5.x is not an option.
You can use next trick:
void setNewPos(QGraphicsItem *item, QPointF pos)
{
item->resetTransform();
QTransform trans = item->transform();
item->setTransform(trans.translate(pos.x(), pos.y()));
}
Now, you can call this func:
QPushButton *btn = new QPushButton("Hello, people!");
QGraphicsProxyWidget *wdgItem = scene->addWidget(btn);
setNewPos(wdgItem, view->mapToScene(0,0)); // There's scenePos can have any coords

Qt Qbrush issue

What is the difference in the following code,
QGraphicsScene * scence = new QGraphicsScene();
QBrush *brush = new QBrush((QColor(60,20,20)));
scence->setBackgroundBrush(*brush);
QGraphicsView *view = new QGraphicsView();
view->setScene(scence);
//view->setBackgroundBrush(*brush);
//view->setCacheMode(QGraphicsView::CacheBackground);
view->showFullScreen();
gives black color background
QGraphicsScene * scence = new QGraphicsScene();
QBrush *brush = new QBrush();
brush->setColor(QColor(60,20,20));
scence->setBackgroundBrush(*brush);
QGraphicsView *view = new QGraphicsView();
view->setScene(scence);
//view->setBackgroundBrush(*brush);
//view->setCacheMode(QGraphicsView::CacheBackground);
view->showFullScreen();
it gives nothing.
As the Qt doc says :
QBrush::QBrush ()
Constructs a default black brush with the style Qt::NoBrush (i.e. this brush will not fill shapes).
In your second example, you have to set the style of the QBrush object by setStyle(), for example with Qt::SolidPattern.
QGraphicsScene * scence = new QGraphicsScene();
QBrush *brush = new QBrush();
brush->setStyle(Qt::SolidPattern); // Fix your problem !
brush->setColor(QColor(60,20,20));
scence->setBackgroundBrush(*brush);
QGraphicsView *view = new QGraphicsView();
view->setScene(scence);
//view->setBackgroundBrush(*brush);
//view->setCacheMode(QGraphicsView::CacheBackground);
view->showFullScreen();
Hope it helps !
An alternate approach that achieves the same result is to put the color in the brush constructor, and that applies a default style of solid:
QBrush *brush = new QBrush (QColor (60, 20, 20));
The constructors that take a color have an optional parameter for the style, which defaults to Qt::SolidPattern. Both approaches produce the same result, but this one uses two fewer lines of code.

Resources