Jump to content

  • Log In with Google      Sign In   
  • Create Account

TheComet

Member Since 02 Oct 2013
Offline Last Active Mar 29 2016 06:23 PM

Topics I've Started

Qt - Resizing issues, minimum size seems to be ignored

20 March 2016 - 02:50 PM

I have created a Qt application with the following structure:
 
.
└── QMdiArea
    └── QTabWidget
        └── HeaderDataBrowser
            └── QVBoxLayout
                └── QSplitter
                    ├── QScrollArea1
                    │   └── QVBoxLayout
                    │       └── QTreeWidget
                    └── QScrollArea2
                        └── QVBoxLayout
                            ├── QwtPlot1
                            └── QwtPlot2
I'm having multiple issues.
1) It appears the parent widgets of the QwtPlot widgets are ignoring the minimum size constraints. The plots just start overlapping when things get small.
2) Even though the QwtPlot widgets are inside a QScrollArea, no scrollbars ever appear, even when resizing ridiculously small. Why?
3) Issue 1) applies to a lot of the other parent widgets. They just ignore the minimum size constraints of their child widgets.

 
This video demonstrates the issues I'm having.
1) The first run shows that the app can be scaled right down to a size that shouldn't be possible.
2) I then set the minimum size of both QwtPlot widgets to 200, 200. Now the plots don't resize smaller than 200, 200, but they begin overlapping each other. What I really want is to restrict the app's minimum size so that doesn't happen.
3) I then set the minimum size of the splitter widget to 300, 300 and show that the parent widgets of the application simply do not care.
 

 
Here is the relevant code for my HeaderDataBrowser widget (this is added as a child to the QTabWidget):
 

 
HeaderDataBrowser::HeaderDataBrowser(QWidget* parent) :
	QWidget(parent),
	treeWidget_(NULL),
	plotLayout_(NULL)
{
	// Header data tree goes on the left side, TxSeq plots on the right
	QVBoxLayout* browserLayout = new QVBoxLayout;
	QSplitter* splitter = new QSplitter(this);
	browserLayout->addWidget(splitter);
	setLayout(browserLayout);

	// Create scroll area and put a tree view inside it. Then add the scroll
	// area to the left side of the splitter
	QScrollArea* scroll = new QScrollArea;
	scroll->setWidgetResizable(true);
	splitter->addWidget(scroll);
	QVBoxLayout* scrollLayout = new QVBoxLayout;
	scroll->setLayout(scrollLayout);
	treeWidget_ = new QTreeWidget;
	scrollLayout->addWidget(treeWidget_);

	// Create layout on right side of splitter. This is where the plots are
	// inserted. Also add it to a scroll area, but disable horizontal
	// scrolling.
	QScrollArea* plotArea = new QScrollArea;
	//plotArea->setWidgetResizable(true);
	//plotArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	splitter->addWidget(plotArea);
	plotLayout_ = new QVBoxLayout;
	plotArea->setLayout(plotLayout_);
}
 

// ----------------------------------------------------------------------------
QwtPlot* HeaderDataBrowser::addPlot()
{
	QwtPlot* plot = new QwtPlot;
	plot->setTitle("Tx Sequence");
	plot->setMinimumSize(100, 100);
	plotLayout_->addWidget(plot);

	// Add a dotted grid
	QwtPlotGrid* plotGrid = new QwtPlotGrid;
	plotGrid->enableX(true);
	plotGrid->enableY(true);
	plotGrid->setMajorPen(QPen(Qt::black, 0, Qt::DotLine));
	plotGrid->setMinorPen(QPen(Qt::gray,  0, Qt::DotLine));
	plotGrid->attach(plot);

	// Legend
	QwtPlotLegendItem* legend = new QwtPlotLegendItem;
	legend->setAlignment(Qt::AlignRight | Qt::AlignTop);
	legend->attach(plot);

	// Axis titles
	plot->setAxisTitle(QwtPlot::yLeft, "Amplitude");
	plot->setAxisTitle(QwtPlot::xBottom, "Time");

	return plot;
}

Trying to write a startup script for sympy

24 October 2015 - 09:37 AM

Hey guys

 

I have the following script:

 

#!/usr/bin/env python3


from numpy import *
from matplotlib.pyplot import *
from sympy import init_session


if __name__ == '__main__':
    init_session(auto_int_to_Integer=True, ipython=True, pretty_print=True)
This will drop you to a CLI once it completes. Here's the problem: It seems none of the functions from numpy or matplotlib.pyplot were imported. If I use one, say linspace, I get:
 
In [1]: linspace
NameError: name 'linspace' is not defined
How can I import custom things into the command line environment?

Worst Hotfixes

11 August 2015 - 05:26 AM

In this thread we share stories of some of the worst hotfixes we've seen and/or applied.

 

In a game I had to present I was experiencing an extremely obscure bug where after some time pointers would randomly point to garbage values, crashing the game. I had an hour to get it working before the presentation.

 

I spent 45 minutes trying to reproduce it with no success. It happened at seemingly random times, but for some reason it was always the same two pointers that were modified.

 

Seeing as I was running out of time, I ended up inserting checks which would replace the garbage value (when it occurred) with the correct value again - the correct value I knew because I saw it in the debugger and it seemed to remain consistent.

if(game->settings_doc != 0x63e1b0)
    game->settings_doc = 0x63e1b0; /* from debugger */

After the presentation I sat down with valgrind and found the problem. A buffer overrun was writing into memory it wasn't supposed to.


Breaking out of a nested loop

25 July 2015 - 12:13 PM

I'm a little disappointed to say the least that breaking from a nested loop feels this dirty in C/C++. It's not an uncommon occurrence, and yet, the "cleanest" solution we have is to use a label and a goto statement. 

 

(Obligatory xkcd joke)

 

In C/C++ the "cleanest" code for breaking from an inner loop:

int i, j;
for(i = 0; i < 10; i++) {
    for(j = 0; j < 10; j++) {
        if(i - 1 == j + 1)
            goto outer;
    }
}
outer:

I feel like we need a new keyword. Perhaps a break_harder or combo_break keyword to break from 2 loops or something?

 

Turns out PHP has this feature. In PHP:

<?php
for($i = 0; $i < 10; $i++) {
    for($j = 0; $j < 10; $j++) {
        if($i - 1 == $j + 1)
            break 2;
    }
}
?>

In Java you can use named blocks to achieve the same result:

outer: {
    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            if(i - 1 == j + 1)
                break outer;
        }
    }
}

How do you guys do this in C/C++? Do you think having a break statement like in PHP would be beneficial in C/C++?

 

People have told me to extract the loops into a separate static function and use return instead of a goto. Do you think this is better practice?


Java Integer and Double memory question

01 July 2015 - 04:14 PM

public class Test {
    public static void main(String[] args) {
        Double d11 = 12.45;
        Double d12 = 12.45;


        Double d21 = 12.45;
        Double d22 = new Double(12.45);


        Integer i11 = 10;
        Integer i12 = 10;


        Integer i21 = 10;
        Integer i22 = new Integer(10);


        System.out.println((d11 == d12 ? "true" : "false"));
        System.out.println((d21 == d22 ? "true" : "false"));
        System.out.println((i11 == i12 ? "true" : "false"));
        System.out.println((i21 == i22 ? "true" : "false"));
    }
}
 

Can someone explain to me why the output is this?

false
false
true
false

Why are the integers implicitly referencing the same Integer object but the doubles are not? This can be seen when looking at the memory locations:

 

zxBjQWv.jpg


PARTNERS